繁体   English   中英

asp.net MVC将服务器值传递给隐藏字段

[英]asp.net MVC pass server value to hidden field

从我的OnePageCheckout.cshtml视图中,我调用ajax控制器

@Html.Hidden("StepContent", (string)ViewBag.newAddress)  @* never work *@
$.ajax({
    cache: false,
    url: this.saveUrl,
    data: $(this.form).serialize(),
    type: 'post',
    success: this.nextStep,  // still stay in the same page
    complete: this.resetLoadWaiting,
    error: Checkout.ajaxFailure
});
public ActionResult OpcSaveBilling(FormCollection form) {    
    ViewBag.newAddress="abc";
    return Json(new {
        update_section = new UpdateSectionJsonModel() {
            name = "confirm-order",
            html = this.RenderPartialViewToString("OpcConfirmOrder",  confirmOrderModel)
        },
        goto_section = "confirm_order"
    });
}

如何使用控制器中的值更新隐藏输入的状态?

更新2:

var Billing = {
form: false,
saveUrl: false,

init: function (form, saveUrl) {
    this.form = form;
    this.saveUrl = saveUrl;
},



save: function () {
    if (Checkout.loadWaiting != false) return;

    Checkout.setLoadWaiting('billing');

    $.ajax({
        cache: false,
        url: this.saveUrl,
        data: $(this.form).serialize(),
        type: 'post',
        success: function (data) {
            this.nextStep;   << nextStep won't be called !!  but it works for success:  this.nextStep
        },
        complete: this.resetLoadWaiting,
        error: Checkout.ajaxFailure
    });


},

resetLoadWaiting: function () {
    Checkout.setLoadWaiting(false);
},

nextStep: function (response) {
    alert('aa');
    if (response.error) {
        if ((typeof response.message) == 'string') {
            alert(response.message);
        } else {
            alert(response.message.join("\n"));
        }

        return false;
    }
    $('#StepContent').val($("#billing-address-select").find('option:selected').text());

    Checkout.setStepResponse(response);
}

};

在ajax调用后更改JS中的状态,

$.ajax({
    cache: false,
    url: this.saveUrl,
    data: $(this.form).serialize(),
    type: 'post',
    success: function (data) {
          $("#StepContent").val(data.status);
           this.nextStep;        
    },  
    complete: this.resetLoadWaiting,
    error: Checkout.ajaxFailure
});

和控制器通过状态的JSON

public ActionResult OpcSaveBilling(FormCollection form) {    
    ViewBag.newAddress="abc";
    return Json(new {
        update_section = new UpdateSectionJsonModel() {
            name = "confirm-order",
            html = this.RenderPartialViewToString("OpcConfirmOrder",  confirmOrderModel),            
        },
        status = "abc",
        goto_section = "confirm_order"
    });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM