how to pass parameter from @Url.Action to controller function

后端 未结 10 819
一生所求
一生所求 2020-12-02 19:42

I have a function CreatePerson(int id) , I want to pass id from @Url.Action.

Below is the reference code:

pub         


        
10条回答
  •  难免孤独
    2020-12-02 20:28

    If you are using Url.Action inside JavaScript then you can

    var personId="someId";
    $.ajax({
      type: 'POST',
      url: '@Url.Action("CreatePerson", "Person")',
      dataType: 'html',
      data: ({
      //insert your parameters to pass to controller
        id: personId 
      }),
      success: function() {
        alert("Successfully posted!");
      }
    });
    

提交回复
热议问题