Hi,
Is it possible to post data in .ASCX ? I guess NO ! If so, how I can accomplish this ? Here is what I am trying to achieve:
I am planning to create TABs in asp.net mvc page. Each and every tab will have different functionality with CREATE/EDIT/DELETE operations. I was thinking that I can create .ASCX and do RenderPartial in .ASPX. But we can't do post in .ASCX ? Is there any other way to do this ? Please let me know. Thanks !
views:
94answers:
2
A:
With MVC, you don't post to files, you post to controller actions. So you can have forms anywhere you want in your views.
mgroves
2009-07-16 18:36:45
^^What he said. Each control can have it's own form -- or multiple -- and post to any controller it chooses. If we're missing the point, please elaborate or provide sample code.
andymeadows
2009-07-16 22:21:57
+1
A:
What mgroves and andymeadows are talking about is simply this;
In your view;
<% Html.RenderPartial("MyPartialControl"); %>
In your partial control, maybe;
<% using (Html.BeginForm("UpdateDatabase_Action", "Controller", FormMethod.Post)) {%>
<%= Html.TextBox("MyField", Model.MyField %>
<input type="submit" value="Submit" class="submitButton" />
<% } %>
In your controller;
public ActionResult UpdateDatabase_Action(FormCollection collection)
{
MyFormViewModel fvm = new MyFormViewModel();
TryUpdateModel(fvm);
//do something with you data
}
Rinse, lather and repeat for each other action / partial control.
Hope this helps.
griegs
2009-07-17 04:33:04
Also, you may want to consider JSON to do this as then you can do a partial postback instead of full postback to a controller action.Much better user experiance.
griegs
2009-07-17 04:46:03