本文介绍了如何将viewbag数据传递给knockout.js [data-bind]模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



任何人都可以告诉我如何传递数据绑定文本和值。我需要分配从下拉列表中选择的值,并需要绑定到我的Knockout.js模型



预先谢谢



我尝试过:



示例代码:

C#code

XYZDataAccess objState = new XYZDataAccess();

List< SelectListItem> objSelectList = new List< SelectListItem>();

List< state> allStates = objState.GetAllStates(out errorCode);

foreach(all obates中的状态objSt)

{

SelectListItem objitem = new SelectListItem();

objitem.Text = objSt.Abbreviation;

objitem.Value = objSt.Abbreviation;

objSelectList.Add(objitem);

}

ViewBag.AllStatesList = objSelectList;





abc.cshtml



data-bind =text:style =display:none>

@ Html.DropDownList(State,(IList< SelectListItem>)ViewBag.AllStatesList,,new { data_bind =value:,@ style =height:23px ;宽度:41px;边框:1px#999; border-radius:5px});

Hi Guys,

Can any one please tell me how to pass the data-bind text and value. i need to assign the value which was selected from the dropdownlist and need to bind to my Knockout.js model

Thanks In advance

What I have tried:

Sample Code:
C# code
XYZDataAccess objState = new XYZDataAccess();
List<SelectListItem> objSelectList = new List<SelectListItem>();
List<state> allStates = objState.GetAllStates(out errorCode);
foreach (State objSt in allStates)
{
SelectListItem objitem = new SelectListItem();
objitem.Text = objSt.Abbreviation;
objitem.Value = objSt.Abbreviation;
objSelectList.Add(objitem);
}
ViewBag.AllStatesList = objSelectList;


abc.cshtml

data-bind="text:" style="display:none">
@Html.DropDownList("State", (IList<SelectListItem>)ViewBag.AllStatesList, "", new { data_bind = " value: ", @style = "height:23px; width:41px;border: 1px #999;border-radius:5px" });

推荐答案


这篇关于如何将viewbag数据传递给knockout.js [data-bind]模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 13:42