【问题标题】:binding knockout bindings to an MVC razor model将敲除绑定绑定到 MVC 剃须刀模型
【发布时间】:2017-07-06 09:24:26
【问题描述】:

我有以下淘汰赛

     <select multiple="multiple" height="5" data-bind="options:allItems, 
 selectedOptions:selectedItems"> </select>

上面生成了敲除脚本中“observableArray”中所有项目的列表。

我需要以某种方式绑定它,就好像它是 razor 中的 @html.etc 元素一样。

例如,我有以下

     @using (Html.BeginForm("SubmitFull", "ENCOUNTER", null))

         {

        @Html.HiddenFor(model => model.Name)
      @Html.ValidationSummary(true)
      <fieldset>
         <legend>ENCOUNTER</legend>
         <div class="editor-label">
            @Html.LabelFor(model => model.Date)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Date)
            @Html.ValidationMessageFor(model => model.Date)
        </div>

所以当我点击页面底部的按钮时,我在视图顶部定义的模型

     @model MVC_MONGODB.Models.PATIENT.Patient

现在将加载一个“日期”属性和一个“名称”属性。

我还需要使用淘汰赛 observableArray 中的值加载模型。我以前从未这样做过,我不确定最好的方法是什么,甚至 任何可能的方式,我什至不能 100% 确定这是可能的。

http://knockoutmvc.com/ 似乎是一个很有前途的参考。

使用“ValueUpdate”似乎是一种可能性,或者可能是某处的(输入类型=“隐藏”)元素..

我想基本上从我在这个问题顶部提到的淘汰代码中获得文本框,就像它实际上在里面一样

 @Html.TextAreaFor(model => model.ChiefComplaintsStr, 5, 100, new { 
  HtmlAttributes = new { } })

【问题讨论】:

    标签: asp.net-mvc razor knockout.js


    【解决方案1】:

    您可以使用控件的HtmlAttributes 设置淘汰赛相关属性,例如...

    @Html.HiddenFor(model => model.ChiefComplaintsStr, htmlAttributes: new { @data_bind = "put knockout binding here"})
    

    【讨论】:

    • 有没有办法让 TextAreaFor 隐藏?
    • 我不明白你的意思?请澄清
    • 您上面提到的代码应该会生成一个加载了敲除绑定值的文本框,对吧?如果是这样,我实际上需要对用户隐藏该框,因为用户已经可以在淘汰赛生成的框中看到淘汰赛绑定中的项目
    • 也许把你提到的代码放在一个div中,并让css使用display属性隐藏它?
    • 那为什么不直接使用隐藏的输入标签呢。即:@Html.HiddenFor(model =&gt; model.ChiefComplaintsSt)
    猜你喜欢
    • 2014-08-18
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    相关资源
    最近更新 更多