i'm using html.beginform , trying pass supplied value of textbox "archname" post, how can that? mean should add instead of "somestring"?
<% using (html.beginform("addarchive", "explorer", new { name = "somestring" }, formmethod.post)) { %> <%= html.textbox("archname")%>
the name referring name attribute of form html element, not posted values. on controller can access few ways.
with no parameter in controller method:
[acceptverbs(httpverbs.post)] public actionresult addarchive() { string archname = httpcontext.reqest.form["archname"] return view(); }
with formcollection
parameter in controller method:
[acceptverbs(httpverbs.post)] public actionresult addarchive(formcollection form) { string archname = form["archname"]; return view(); }
with model binding:
//poco class archive { public string archname { get; set; } } //view <%@ page language="c#" inherits="system.web.mvc.viewpage<namespace.archive>" %> <%= html.textboxfor(m => m.archname) %> [acceptverbs(httpverbs.post)] public actionresult addarchive(archive arch) { string archname = arch.archname ; return view(); }
Comments
Post a Comment