c# - Help with mapping ActionLinks to Methods in Controllers (ASP.NET MVC2) -
c# - Help with mapping ActionLinks to Methods in Controllers (ASP.NET MVC2) -
i'm on first mvc project , still haven't got finish hang of it. ran issue:
i have in view (home/index.aspx)
<% using (html.beginform()) { %> <fieldset> <p> <%: html.textbox("a")%> <%: html.textbox("b") %> <%: html.actionlink("submit", "create", "home")%> </p> </fieldset> <% } %>
i have in controller (controllers/homecontroller.cs)
[acceptverbs(httpverbs.post)] public actionresult create(formcollection formvalues) { homecoming view("index"); }
i haven't changed default routes in global.asx
when nail submit, "the resource cannot found error". however, if alter actionlink to
<input type="submit" value="save" />
and method in controller to:
[acceptverbs(httpverbs.post)] public actionresult index(formcollection formvalues) { homecoming view("index"); }
it works fine.
i'm little confused because if i'm specifying exact action method name , controller in actionlink (<%: html.actionlink("submit", "create", "home")%> ), why matter whether name method create or index?
you have [acceptverbs(httpverbs.post)]
restricts http post requests. since action link get, it's not using method. presumably have two index methods, 1 of doesn't have attribute , accepts requests.
c# .net asp.net-mvc asp.net-mvc-2 asp.net-mvc-routing
Comments
Post a Comment