Generating an action URL in JavaScript for ASP.NET MVC

前端 未结 9 1124
梦毁少年i
梦毁少年i 2020-12-09 09:52

I\'m trying to redirect to another page by calling an action in controller with a specific parameter. I\'m trying to use this line:

window.open(\'<%= Url.         


        
9条回答
  •  一向
    一向 (楼主)
    2020-12-09 10:10

    Just if someone is still looking for this. The controller action can have normal parameters or a model object with these fields. MVC will bind the valus automatically.

     var url = '@Url.Action("Action", "Controller")';
     $.post(url, {
          YearId: $("#YearId").val(),
          LeaveTypeId:  $("#LeaveTypeId").val()
     }, function (data) {
          //Do what u like with result
     });
    

提交回复
热议问题