开发者

Asp.Net MVC Post Controller Not being hit

I've got an Asp.Net mvc web app that has a controller action to handle a post with an int as a parameter. I've set a breakpoint in the action and it is never getting hit. Here is the controller action setup: 开发者_开发知识库

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult AddTestNumber(int number)
    {

And here is the jquery that calls the action:

$.post("/testController/AddTestNumber/852852");

I've tested it with no parameters and it hit the breakpoint. I havent changed any routing, so thats set to default.

This seems like it should be very simple fix that I'm overlooking


A couple of things to try:

Your URL doesn't need to contain 'Controller'. i.e.

$.post("/Test/AddTestNumber/852852");

If you want the parameter to be in the URL, rather than in the query-string, and you are using default routing, then I believe the parameter needs to named 'id'. i.e.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddTestNumber(int id)
{

Otherwise, you need to pass it via the query-string. i.e.

$.post("/Test/AddTestNumber?number=852852");

or add custom routing rules.

I hope one of those helps you out.


yes the fix is easy. if you did not change routing, in stead of int number, use int id. now the router looks for a 'number', but in your url you dont have a number, just an id.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜