无法使用knockout ViewModel绑定cshtml文件中的<select>

时间:2016-05-27 14:06:34

标签: javascript razor model-view-controller knockout.js

这是我的ViewModel代码 var urlPath = window.location.pathname; $(function(){     ko.applyBindings(CreateVM); }); var CreateVM = { EmployeeId:ko.observable(),   名称:ko.observable(),     性别:ko.observableArray([&#34;男性&#34;,&#34;女性&#34;]),     性别:ko.observable(),    城市:ko.observable()    SaveEmployee:function(){         $就({             url:urlPath +&#39; /创建&#39;,             输入:&#39; post&#39;,             dataType:&#39; json&#39;,             数据:ko.toJSON(this),             contentType:&#39; application / json&#39;,             异步:真实,             成功:功能(结果){                 window.location.href = urlPath +&#39; / Employees / Index&#39 ;;                 警告(&#34;在createVM和#34中取得成功;);             },             错误:函数(错误){                 if(err.responseText ==&#34; success&#34;){                     window.location.href = urlPath +&#39; / Employees / Index&#39 ;;                     alert(&#34; createVM&#34中的错误成功;);                 } else {                     警报(err.responseText);                     alert(&#34; createVM&#34中的错误;);                 }                 警报(&#34;消息&#34);             },             完成:function(){             }         });     } }; 这是Create.cshtml标记,既不预先填充也不检索值。正在检索所有其他字段,如EmployeeId,City和Name。 &lt; div class =&#34; editor-label&#34;&gt;     性别 &LT; / DIV&GT; &lt; div class =&#34; editor-field&#34;&gt;     &lt; select data-bind =&#34;选项:性别,价值:性别&#34;&gt;&lt; / select&gt; &LT; / DIV&GT;

0 个答案:

没有答案