Thanks for reaching out!
Below are some simple steps which are helpful
- Create a ViewModel: Put all textbox fields inside one class. public class UpdateVM { public string Name { get; set; } public string Address { get; set; } }
- Bind View to Model: @model UpdateVM
- Use BeginForm + TextBoxFor
using (Html.BeginForm("Update","Home",FormMethod.Post))
{
@Html.TextBoxFor(m => m.Name)
@Html.TextBoxFor(m => m.Address)
<button type="submit">Save</button>
}
- Receive Model in Controller [HttpPost] public IActionResult Update(UpdateVM model) { // Updated values come automatically here return View(); }
- Avoid Session Do NOT use HttpContext.Session for passing form data. Model binding already handles everything cleanly.