简体   繁体   English

在视图状态上保留数据并中继到Knockout.JS

[英]Persisting data on view state and relaying to Knockout.JS

I'm currently working on an asp.net web form that uses Knockout, Bootstrap, and JQuery. 我目前正在使用asp.net Web表单,该表单使用Knockout,Bootstrap和JQuery。 I'm having an issue with data persistence through "Wizard steps." 我在通过“向导步骤”进行数据持久化时遇到了问题。

What I would like to do is take in the mailing state of the client and persist it through to other pages, from there use Knockout to make fields visible and also create validation. 我想做的是进入客户端的邮件状态,并将其持久化到其他页面,然后使用Knockout使字段可见并创建验证。

I've read that you can use hidden states to accomplish this but I've had issues getting the value to pass to Knockout and ultimately getting the other fields to show. 我读过您可以使用隐藏状态来完成此操作,但在将值传递给Knockout并最终显示其他字段时遇到了问题。

Here is the c# that does all the steps page to page. 这是执行所有步骤的C#。

    protected void StepChanged(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            if (QuoteWizard.ActiveStepIndex == 0)
                txtFirstName.Focus();

            if (QuoteWizard.ActiveStepIndex == 1)
            {
                Session["State"] = ddlState.Value;
                rblMailAddr.Focus();
            }

            if (QuoteWizard.ActiveStepIndex == 3)
            {
                txtDriverFName1.Value = txtFirstName.Value;
                txtDriverMI1.Value = txtMI.Value;
                txtDriverLName1.Value = txtLastName.Value;

                String DOB;
                DOB = Convert.ToDateTime(txtDOB.Value).ToString();
                txtDriverDOB1.Value = DOB;

                txtDriverFName1.Focus();
            }

I find it odd that the txtDriverFName1.Value = txtFirstNAme.Value; 我觉得txtDriverFName1.Value = txtFirstNAme.Value;很奇怪 passes properly but I can't get the state from a drop down list or the date of birth to pass from one step to the other. 通过正确,但我无法从下拉列表中获得状态,也无法从出生日期将状态从一个步骤传递到另一步骤。

   <select id="ddlState" runat="server" class="form-control" data-bind="value: MailState, updateValue: 'afterkeydown'">

Followed by the list of states, then I try to pass it to knockout to make fields visible: 接下来是状态列表,然后我尝试将其传递给淘汰赛,以使字段可见:

    self.MailState = ko.observable("", { persist: "MailState" });

However, once I reach the next step the values in the ViewState are dropped and 但是,一旦我进行下一步,就将ViewState中的值删除并

    <div class="btn-group" data-toggle="buttons" style="padding-left: 10px" data-bind="visible: MailState() == 'CA'">

no longer becomes visible even when CA is selected in the previous viewstate. 即使在先前的视图状态中选择了CA,也不再可见。

So how would I persist the value of my drop down list through 2 or more steps in the QuoteWizard.ActiveStepIndex and have that assigned to "MailState()" subsequently activating Knockout? 那么,如何通过QuoteWizard.ActiveStepIndex中的2个或更多步骤来保持下拉列表的值,并将其分配给“ MailState()”,然后激活Knockout?

in data-bind the bindinghandler handle to excute expression, then visible bindinghandler will unwrap it to value from observable. 在数据绑定中,bindinghandler句柄执行表达式,然后可见的bindinghandler会将其解包为可观察的值。 But in your code you use 但是在您的代码中您使用

data-bind="visible: MailState == 'CA'" //MailState is observalbe then like function() == 'CA' - that not right

should change to: 应该更改为:

data-bind="visible: MailState() == 'CA'" 

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

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