asp.net - How to handle a POST request to a URL that contains route parameters? -


i'm working on asp.net mvc4 web app, , have controller method handling get request id in url, ...

[portalauthorization] public actionresult view(int id) {     // individual ftp log     portalftplog log = portalftplogs.get(id);      if (log == null)     {         tempdata["error"] = "the provided ftp log id not exist.";         return redirecttoaction("index");     }      // available matters tie uploads     viewbag.matters = portalmatters.get();      return view(log); } 

in view controller method, have form can update it, want post same url. url foo.com\items\1. thats function above handles.

how make function handles post request function requires parameter, though? in previous post handlers create formscollection param, when add param list function, id param null.

[httppost] [portalauthorization] public actionresult view(formcollection collection, int id) {     portalftplog log = portalftplogs.get(id);      if (log == null)     {         tempdata["error"] = "the provided ftp log id not exist.";         return redirecttoaction("index");     }      // update matter id , save database     log.matter = convert.toint32(collection.get("matter"));     log.save();      tempdata["notice"] = "the ftp log meta data has been updated.";      return redirecttoaction("view", new { id = id }); } 

thank you!

you need provide routevalues in html.beginform on view:

 @using (html.beginform(new {id = someintidvalue}))  {      // form code    } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -