Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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" });
Posted

1 solution

HI,

Please refer to the following link :

json - Need to pass initial viewmodel data from ASP.NET MVC to knockout.js - Stack Overflow[^]

Hopefully it will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900