C# 当单击ajax中的按钮将值传递给控制器并显示回同一视图页面时,页面只加载加载数据的数组

C# 当单击ajax中的按钮将值传递给控制器并显示回同一视图页面时,页面只加载加载数据的数组,c#,ajax,asp.net-mvc,asp.net-mvc-viewmodel,C#,Ajax,Asp.net Mvc,Asp.net Mvc Viewmodel,表行是在页面加载时使用ajax生成的,如下所示 $.ajax({ url: '/consultation/GetPrescHistoryList', type: 'POST', data: $('#frmPrescHistoryTable').serialize(), // it will serialize the form data //dataType: 'json', success: fun

表行是在页面加载时使用ajax生成的,如下所示

        $.ajax({
        url: '/consultation/GetPrescHistoryList',
        type: 'POST',
        data: $('#frmPrescHistoryTable').serialize(), // it will serialize the form data
        //dataType: 'json',
        success: function (data) {

            var rowNo = 0;
            for (var i = 0; i < data.length; i++) {
                rowNo += 1;
                $("#LoadPrescHistoryTable tbody").append("<tr Class='odd gradeX'>" +
                            "<td>" + rowNo + "</td>" +
                            "<td>" + data[i].description + "</td>" +
                            "<td>" + data[i].UserName + "</td>" +
                            "<td><button type='button' class='repeat btn btn-default' data-id='" + data[i].dgid + "'>Repeat</button></td>" +
                "</tr>");
            }

            alert('LoadPrescHistoryTable has been loaded.');

        },
        error: function () {
            alert('Ajax Submit Failed ...');
        }
    }); // end ajax

    var baseUrl = '@Url.Action("GetPrescDetailsObj", "consultation")';
    $("#LoadPrescHistoryTable tbody").on('click', '.repeat', function ()                                                                                          {
        location.href = baseUrl + '?dgid=' + $(this).data('id');
    });
下面是用于将对象传递回视图的控制器,一个在文本框中,另一个在标签中

    public ActionResult GetPrescDetailsObj(string dgid)
    {
        PrescriptionVM Prescription = new PrescriptionVM();
        PatientLookupVM Patient = new PatientLookupVM(Prescription);
        Patient.LoadDrugObj = Prescription.GetDrugObj(dgid);
        dynamic data = new
        {
            tradename = Patient.LoadDrugObj.tradename,
            remarks = Patient.LoadDrugObj.remarks

        };
        return Json(data, JsonRequestBehavior.AllowGet);

    } 

当我单击repeat按钮时,页面将替换为我调用的数据数组。有人能告诉我我做错了什么吗?

调试代码时会发生什么?@SimonPrice对不起,我的错,我最近添加了一个代码,现在它工作了,不再出现404错误,只是页面被ajax调用中的数据数组替换。您可以发布一些html代码吗?您使用的是@html.begin表单还是纯html表单标记?@sriram只是纯html表单标记。对于表行中的按钮,我没有放置任何表单标记。但是对于整个表单标记,我使用这个
    public ActionResult GetPrescDetailsObj(string dgid)
    {
        PrescriptionVM Prescription = new PrescriptionVM();
        PatientLookupVM Patient = new PatientLookupVM(Prescription);
        Patient.LoadDrugObj = Prescription.GetDrugObj(dgid);
        dynamic data = new
        {
            tradename = Patient.LoadDrugObj.tradename,
            remarks = Patient.LoadDrugObj.remarks

        };
        return Json(data, JsonRequestBehavior.AllowGet);

    }