jQuery to call Action Method in ASP.NET MVC C# by Ajax

后端 未结 4 426
夕颜
夕颜 2020-12-16 18:09

I have tried for hours to get this working, and I am really hoping one of you knows (a heck of a lot) more about this than I. When the client keys up in a textbox, I would l

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 18:54

    It looks like you're putting the URL of the MVC route in the action attribute of your

    tag. I can't see what that attribute looks like because you didn't post your html, but from what I can see the value of that attribute might be wrong.

    Most of the time, the URL to a specific MVC action is http://ServerDomain/Path(IfAny)/ControllerName/ActionName. For example, if you have a controller and action like this...

    public class StackController
    {
        [HttpPost]
        public ActionResult Overflow()
        {
            return View();
        }
    }
    

    ...and your ASP.NET application is deployed to www.example.com, the URL in the action attribute of your tag would be http://www.example.com/Stack/Overflow.

    Of course, it's possible for other settings in your ASP.NET MVC to change these URLs, such as the route setup in your global.asax's RegisterRoutes method, or perhaps if your controllers are divided into Areas. If the URL of your looks correct, please post the html along with any relevant controller routing code in your ASP.NET app.

    If your form is inside of a Razor view (cshtml file), you can use to generate the correct form URL.

提交回复
热议问题