I have a grid with data on it. When I want to edit the data, I need to press the edit button and a new edit form will open with the current data from the row.
For the textboxes I use:
@Html.EditorFor(model => model.SubStatus)
Now the issue is the dropDownList. Here is my code. the initial value is always blank?
CSHTML code:
@(Html.Kendo().DropDownListFor(m => m.SubType)
.Name("SubsType")
.DataTextField("SubType1")
.DataValueField("SubType_ID")
.DataSource(source =>
{
source.Custom()
.ServerFiltering(true)
.Type("aspnetmvc-ajax")
.Transport(transport =>
{
transport.Read("GetType", "Welcome");
})
.Schema(schema =>
{
schema.Data("Data")
.Total("Total");
});
})
)
Razor code:
public JsonResult GetSubType([DataSourceRequest] DataSourceRequest dropDownRequest)
{
IList<SubType> myViewModels = new List<SubType>();
foreach (SubType subType in db.ExecuteStoredProcedure<SubType>("proc_getType", null))
{
SubType subtype = new SubType()
{
SubType_ID = subType.SubType_ID,
SubType1 = subType.SubType1
};
myViewModels.Add(subtype);
}
return Json(myViewModels.ToDataSourceResult(dropDownRequest), JsonRequestBehavior.AllowGet);
}
Right now I get the list from the database. when the dropdownlist is pressed. but I want to set the initial value of the list to be the current value. How to do it?