c# - MVC: How to identify which event on a page calls the controller? -
i have view
has 2 buttons.
one button called create
causes form validation , shows preview of sql query
executed. button called confirm
, performs actual execution of query.
i need identify in controller button clicked perform appropriate action.
this view:
<%using (html.beginform()) { %> <%:html.antiforgerytoken() %> <div> <fieldset> <legend>e-safe information</legend> <div id="div1" style="height:10px; margin-bottom:10px" runat="server"> <%:@html.validationmessage("message") %> </div> <%:viewdata["message"] %> <table> <tr> <td><div class="editor-label"><%: html.labelfor(m => m.corporation) %></div></td> <td><div class="editor-field"><%: html.textboxfor(m => m.corporation)%></div></td> <td><%: html.validationmessagefor(m => m.corporation) %></td> </tr> <tr> <td><div class="editor-label"><%: html.labelfor(m => m.region) %></div></td> <td><div class="editor-field"><%: html.textboxfor(m => m.region, new { @id = "regiontextbox", maxlength = 2 })%></div></td> <td><%: html.validationmessagefor(m => m.region) %></td> </tr> <tr> <td><div class="editor-label"><%: html.labelfor(m => m.portfolioname) %></div></td> <td><div class="editor-field"><%: html.textboxfor(m => m.portfolioname) %></div></td> <td><%: html.validationmessagefor(m => m.portfolioname) %></td> </tr> <tr> <td> <input type="submit" value="create" /></td> </tr> </table> </fieldset> </div> <div id="review"> review: <p> <%:viewdata["review"]%> </p> <input id="queryreview" type="submit" value="ok" /> </div> <%} %>
this controller:
public class esafecontroller : controller { private esafeactionservice esafedata { get; set; } protected override void initialize(requestcontext requestcontext) { if (esafedata == null) { esafedata = new esafeactionservice(); } base.initialize(requestcontext); } public actionresult index() { homecoming view(); } [acceptverbs(httpverbs.post)] [validateantiforgerytoken] public actionresult index(esafemodel model) { if (modelstate.isvalid) { esafeactions esafe = new esafeactions(model.corporation, model.region, model.portfolioname); if (esafedata.validatedata(esafe)) { viewdata["review"] = esafedata.createreview(esafe); if (esafedata.create(esafe)) { viewdata["message"] = "e-safe info created!!!"; } } else { modelstate.addmodelerror("message", "the part should 2 characters long."); } } else { modelstate.addmodelerror("message", "creation of info failed. please right errors , seek again."); } homecoming view(model); }
}
thank you
you want wrap content areas in this:
@using (html.beginform("<actionname>", "<controllername>", formmethod.get)) { <input type="submit" value="create" /> }
instead of generic, empty beginform have in use. can specify parts controlled action in controller, input button included within braces.
c# view asp.net-mvc-2 controller
No comments:
Post a Comment