更新局部视图使用Ajax视图、局部、Ajax

2023-09-10 14:53:54 作者:本命07少年

我有以下细节的局部视图,

I have a partial view with the following details,

_PartialTEST.cshtml

@model FreeLance.Web.Models.PArtialTESTModel

@Html.RadioButtonFor(m => m.D1, "true", new { Name = "test1", @id = "g1", @checked = "true" }) @Html.LabelFor(m => m.MSGD1, @Model.V1)
@Html.RadioButtonFor(m => m.D2, "false", new { Name = "test1", @id = "g2" }) @Html.LabelFor(m => m.MSGD2, @Model.V1) 
@Html.RadioButtonFor(m => m.D3, "false", new { Name = "test1", @id = "g3" }) @Html.LabelFor(m => m.MSGD3, @Model.V1) 

这是用来另一种观点认为,

Which is Used in another View,

MainTEST.cshtml

<div id="partialDIV">
       @{
           @Html.Partial("_PartialTEST", Model)
       }                           
</div>

现在在一个事件我想用得到的新值 AJAX

Now During an Event I am trying to get the new values using AJAX

$.ajax({
                type: "GET",
                url: href,               
                traditional: true,
                async: false,
                cache: false,
                contentType: 'application/json',
                data: { DID: DID },
                success: function (data) {
                    debugger;
                    $('#partialDIV').html(data);
                },
                error: function (arg, data, value) {

                }
            });

现在虽然数据拥有所有的值,我无法得到呈现的局部视图。任何帮助,我很想念这里呢?

Now though "data" has all the values, I am unable to get the partial view rendered. Any help, What I am missing here?

推荐答案

在服务器端使用此code来回报您的局部视图::

On the Server side Use this Code to Return your Partial View::

    public PartialViewResult MainTEST()
    {
        var model = new FreeLance.Web.Models.PArtialTESTModel();
        return PartialView("_PartialTEST.cshtml",model);
    }

在你的客户端AJAX做它的成功::一些修改

and in you AJAX on Client Side do some changes on its success::

$.ajax({
            type: "GET",
            url: href,               
            traditional: true,
            async: false,
            cache: false,
            contentType: 'application/json',
            data: { DID: DID },
            success: function (data) {
                debugger;

                $('#partialDIV').empty();
                $('#partialDIV').html(data);
            },
            error: function (arg, data, value) {

            }
        });