【问题标题】:how to bind the data to Html Helper Class after Success of the jquery ajax requestjquery ajax请求成功后如何将数据绑定到Html Helper Class
【发布时间】:2014-02-12 19:31:22
【问题描述】:

您好,有没有人可以帮助我解决以下问题。我有 jquery ajax get(http get) 请求和
有成功数据,问题是如何将数据绑定到 html 表单或 html helper 类 喜欢(@html.Dropdownlist ,@html.TextBox), 实际上,我试图在 jquery 和 ajax 的帮助下将一个视图称为创建和编辑,我一度陷入困境,请帮帮我,,

我的jquery代码是

$.ajax({
    type: 'Get',
    url: geturl,
    data: {
        orderid: $(this).data('id')
    },
    success: function (response) {
        var CustomerID = response.cID;
        var ShipName = response.ShipName;
        $("#CustomerID").html(CustomerID);
        $("#ShipName").html(ShipName);
        return false;
    },
    error: function (e) { alert(e.error); }
});

如何将响应数据绑定到 html 助手类属性,就像我想将 cID 绑定到 CustomerID

我的查看代码是

enter code here
  <form id="myform" >
    <div>`enter code here`
        @Html.Label("Ship Name", "ShipName");
        @Html.TextBox("ShipName", "");
    </div>
    <div class="editor-label">
        @Html.Label("Customer", "CustomerID")
    </div>
    <div class="editor-field">
        @Html.DropDownList("CustomerID", String.Empty)

    </div>

【问题讨论】:

    标签: jquery ajax asp.net-mvc


    【解决方案1】:

    使用val insted of html

    $("#CustomerID").val(CustomerID);
    $("#ShipName").val(ShipName);
    

    【讨论】:

    • 感谢 Jaimin 的工作,有什么办法可以让我们将整个响应数据提供给 Form
    • @Abhi 如果我的代码对您有帮助,则标记为 ans。所以它可能对其他人有帮助。
    猜你喜欢
    • 2012-05-29
    • 1970-01-01
    • 2011-07-21
    • 2018-09-12
    • 2015-08-29
    • 2012-08-26
    • 1970-01-01
    • 2012-12-15
    • 1970-01-01
    相关资源
    最近更新 更多