tags:

views:

41

answers:

2

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"); %>
A: 

The best way is to take all the fields and put them into a partial view and have the main view (Create/Edit) do the different begin forms.

Wil
+1  A: 

Simple. Don't specify the action name in your call to Html.BeginForm. By default the same action name is used for POST as for GET (and similarly for controller). So if you just do:

<% using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))

...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."

Craig Stuntz
I like you general rule of thumb!
Rippo