Click here to Skip to main content
15,444,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys i have a problem passing a value of an element to my controller
this is my controller code:

ASP.NET
[HttpPost]
public IActionResult OnPostMyUploader(IFormFile MyUploader, string empUsername)
{
    // No point loading and resizing the image if we're not going to use it:
    if (MyUploader is null) return new ObjectResult(new { status = "fail" });

    string uploadsFolder = @"\\10.10.10.67\AQSImages\IdPictures\";
    string userfileName = empUsername.ToString() + ".jpg";
    string filePath = Path.Combine(uploadsFolder, userfileName);
    using var fileStream = new FileStream(filePath, FileMode.Create);

    using var image = System.Drawing.Image.FromStream(MyUploader.OpenReadStream());
    using var resized = new Bitmap(image, new System.Drawing.Size(150, 150));
    using var imageStream = new MemoryStream();
    resized.Save(imageStream, ImageFormat.Jpeg);

    imageStream.Seek(0L, SeekOrigin.Begin);
    imageStream.CopyTo(fileStream);
    return new ObjectResult(new { status = "success" });
}


I want to get the value empUserName from View :

HTML
<div class="col-4">
                                    <label class="w-100">Username</label>
                                    <input id="empUsername" class="input-form w-100" disabled>
                                </div>


What I have tried:

ASP.Net MVC How to pass data from view to controller - Stack Overflow[^]
Posted
Comments
Graeme_Grant 5-Jul-22 10:03am    
Your html above is all wrong. Please re-read the approved answer in the link that you provided.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900