How do you pass a model from Editor for model into a controller? (using asp.net)
-
29-06-2021 - |
Question
@model mymodelsnamespace
@using (Html.BeginForm("MyMethodName", "MyContollerName", FormMethod.Post))
{
@Html.EditorFor(m => Model, "Submit", new { multiple = true })
<input type="submit" value="Submit" />
}
I know the code I am going write will be close to whats above
How do I passed the updated model into MyMethodName is i can continue to manipulate it in my controller?
Please provide the signature for MyMethodName and the cshtml to give the model to the method in the controller.
Solution
If you add this code to your controller, it should work.
[HttpPost]
public ActionResult MyMethodName (YourModel model)
{
... some code here.
}
You may find the Model-View-ViewModel pattern interesting.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow