开发者

Parameter passing in ASP.Net MVC

开发者 https://www.devze.com 2023-01-29 08:50 出处:网络
i want to make some questions about asp.net mvc.Actually,i am not familiar with web developing.my questions are i have two controllers,one is login and another one is

i want to make some questions about asp.net mvc.Actually,i am not familiar with web developing.my questions are i have two controllers,one is login and another one is profile.Aft开发者_StackOverflower login,i want to call profile.so,i use this way,

return RedirectToAction("DiaplayProfile","Profile",new { personID = Person.personID});

my problem is parameter that i passed are shown i URL.i don't want to show.In web developing,if we use post method to send data,parameters are not shown in url,is it correct?for me,i need to pass parameter ,but,i don't want to show at url. How i use in post method in MVC RedirectToAction?i also tested with TempData to pass data,but,it's gone after if i make refresh.how i hanlde this?And also, can i use [AcceptVerbs(HttpVerbs.Post)] for solve this problem?

guide me right ways, please.

Regards Chong


You can't do a post as part of a redirect; a redirect must be a get request since you're simply passing the browser the URL to which to redirect. In MVC, having the id as part of the URL is actually considered to be a good thing. I would embrace it. Rather than having the parameter be personID, I would use id so that the default routing can be used. Eventually I'd want to end up with a URL that looks like:

http://example.com/profile/display/1345

where 1345 is the id of the person in question. If you use default routing, that would mean that you have a ProfileController with a Display method that takes a single id parameter (of type int). You would redirect to it using:

return RedirectToAction( "display", "profile", new { id = 1345 } );

BTW, you can't use the AcceptVerbs attribute to control how a redirect is made, only to control what HTTP verbs the action will respond to. In this case, I think you really do want to accept a GET and I think you really do want to have the id in the URL.

0

精彩评论

暂无评论...
验证码 换一张
取 消