I’m using an ASP.NET MVC usercontrol to represent a form for both a “create” mode and an “edit” mode.
The form involves a file upload so looks something like this:
<% using (Html.BeginForm("Create", "News", FormMethod.Post, new { enctype = "multipart/form-data" }))
How can I make it post to the Create action in create mode and Edit action in edit mode?
I’m rendering it in the View like this:
<% Html.RenderPartial("NewsForm"); %>
Simple. Don’t specify the action name in your call to
Html.BeginForm. By default the same action name is used forPOSTas forGET(and similarly for controller). So if you just do:…then you get what you want.
A general rule of thumb for ASP.NET MVC is, “If your code is not doing what you want, try removing some of it.”