May 10, 2012, 12:48 PM
[CLOSED] [Razor] Select Combobox item from model value
Hi there,
I've got several combo boxes such as this one:
I've got several combo boxes such as this one:
fields.Add(Html.X().ComboBox()
.FieldLabel("Service Status")
.LabelAlign(LabelAlign.Top)
.ID("ddlServiceStatus")
.Margins("0 0 0 0")
.LabelWidth(200)
.Width(200)
.EmptyText("--- Please Select ---")
.Cls("form-label")
.DisplayField("ServiceStatusName")
.ValueField("ServiceStatusId")
.Store(store => store.Add(Html.X().Store()
.AutoLoad(true)
.Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
.Url("/Services/RetrieveServiceStatuses/")
.Reader(reader => reader.Add(Html.X().JsonReader()
.Root("data")
.TotalProperty("total")
))
))
.Model(model => model.Add(Html.X().Model()
.Fields(modelFields =>
{
modelFields.Add(Html.X().ModelField().Name("ServiceStatusID"));
modelFields.Add(Html.X().ModelField().Name("ServiceStatusName"));
})
))
)
)
);
The page this field resides on gets on MVC model from the controller on load and I need to use the Model.ServiceStatus value to pre-select the relevant combobox item. I've tried a few methods - using the selecteditems attribute and a load handler but I'm obviously not doing it correctly... What is the correct way to do this in razor syntax?
Last edited by Daniil; May 18, 2012 at 4:53 PM.
Reason: [CLOSED]