简体   繁体   中英

ASP.NET JavaScript onClick function

I have an index.cshtml page, in it there is a button:

 <div>
    @Html.EslButton(T("Create Request").ToString(), "createRequestBtn")

</div>

I then have a javascript onclick function in the same page

   $("#createRequestBtn").on('click', function (event) {

        event.preventDefault(event);
    });

In my HomeController.cs I have a function called CreateRequests:

 public ActionResult CreateRequests(ViewModel model)
        {


            return new EmptyResult();

        }

Question

How do I, through clicking the button, go in to the method CreateRequests in Controller?

Thanks!

$("#createRequestBtn").on('click', function (event) {

    event.preventDefault(event);

    var xhr = new XMLHttpRequest();
    xhr.open("post", "/Home/CreateRequests");
    xhr.send();

});

But you should remove model parameter

public ActionResult CreateRequests()
{

   return new EmptyResult();

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM