Reputation: 9279
I have an Index page in an MVC3 C#.Net web app. The Index View of my Proposal Model contains an input submit button:
<input type="submit" name="Create" id="Create" value="Create New Proposal" style="width: 200px" />
When the button is clicked, I want to invoke the Create View on the Proposal Model. However, I can't get any method in the Proposal Controller to fire when clicking on the "create New" input button. Can I call the Index Post method? The Proposal Create get method? Any ideas?
Upvotes: 2
Views: 13413
Reputation: 11916
You have to write a post method and then use this for displaying your View
@using (Html.BeginForm("YourAction", "Controller", "FormMethod.Post"))
{
//your View code display
}
Upvotes: 2
Reputation: 14941
Try using an HTML Helper like @Html.BeginForm
. See here for clues: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.formextensions.beginform.aspx
In your case try this:
@using (Html.BeginForm("Create", "Proposal")){
......
<input type="submit" value="Submit" />
}
Upvotes: 2
Reputation: 2830
You need your submit button inside a form
and an overloaded ActionResult
in your controller which uses the HttpPost
attribute.
Something like...
Controller
public ActionResult Index()
{
return View(new MyViewModel());
}
[HttpPost]
public ActionResult Index(MyViewModel model)
{
// do stuff with model
}
View
@using(Html.BeginForm())
{
<input type="submit" value="Go" />
}
That would render a form and post it to the Index action result in your controller.
Upvotes: 4