Rendering a simple ASP.NET MVC PartialView using JQuery Ajax Post call

后端 未结 1 1098
再見小時候
再見小時候 2021-02-01 08:39

I have the following code in my MVC controller:

[HttpPost]
public  PartialViewResult GetPartialDiv(int id /* drop down value */)
{
    PartyInvites.Models.GuestR         


        
相关标签:
1条回答
  • 2021-02-01 09:13

    this line is not true: url: "@Url.Action("GetPartialDiv/")" + $(this).val(),

    $.ajax data attribute is already included route value. So just define url in url attribute. write route value in data attribute.

    $(".SelectedCustomer").change( function (event) {
        $.ajax({
            url: '@Url.Action("GetPartialDiv", "Home")',
            data: { id : $(this).val() /* add other additional parameters */ },
            cache: false,
            type: "POST",
            dataType: "html",
            success: function (data, textStatus, XMLHttpRequest) {
                SetData(data);
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题