Passing Parameters from JQuery to Controller Action in ASP.NET MVC 3

I have a web page that is using JQuery to communicate with the backend. I have some POST actions. However, I now have a GET action and I've noticed that the parameter values passed to it are null. My POST actions work just fine. I can't figure out why. From my .html file, I have the following JQuery query: var vm = { emailAddress:"" }; $.ajax({ url: "/myService/myAction", type: "GET", data: JSON.stringify(vm), contentType: "application/json", success: myAction_Succeeded, error: myAction_Failed }); In my controller, I have: public class MyServiceController : Controller { [AcceptVerbs(HttpVerbs.Get)] public ActionResult MyAction(string emailAddress) { return Json(new { address:emailAddress }); } } My route is setup as follows: context.MapRoute( "MyAction", "myService/{controller}/MyAction", new { controller = "MyService", action = "MyAction" } ); I have a hunch that I'm missing something in my route. But I'm not sure what it is. I followed the same syntax I used with my POST actions. Parameters with those actions work just fine. But the parameters with my GET actions, like the one above, have null values. My question is, what am I doing wrong and what if I need to pass multiple parameters? Thank you so much for your help!

以上就是Passing Parameters from JQuery to Controller Action in ASP.NET MVC 3的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准