Is there a way to pass entire object from ASP.NET MVC 5 View to a Controller? This is my situation:
Is there a way to pass the entire object to the Update controller method so it would initially fill the form inputs with the old data? Something like:
@Html.Action("Update me!", "Update", new { objectFromModelList })
And then in the controller
public ActionResult Update(MyType parameter)
{
return View(parameter);
}
Or something like that. Please help, I am new to this and can't find the answer anywhere.
Your objects could be so big! Query string's has a limitation on how much data you can pass via those based on the browser. You should consider passing a unique id value (of the record) and using which get the entire record from db in your action method and pass that to the view.
@foreach(var item in SomeCollection)
{
<tr>
<td> @Html.Action("Update me!", "Update", new { id = item.Id }) </td>
</tr>
}
and in the action method
public ActionResult Update(int id)
{
var item = GetItemFromId(id);
return View(item);
}
Assuming GetItemFromId
method returns the method/view model from the unique id value. Basically you get the entire record using this unique id from your db table/repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With