Skip to content

DevExpress-Examples/asp-net-mvc-editors-edit-model-fields

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Editors for ASP.NET MVC - How to use data editors to edit Model fields

This example demonstrates how to use data editors in bound and unbound modes to edit Model fields.

Use editors to edit Model fields

Overview

Use the editor's PreRender property to specify multiple selected items based on the enumerable Model field.

settings.PreRender = (sender, e) => {
    ASPxCheckBoxList cbl = (ASPxCheckBoxList)sender;
    foreach(ListEditItem item in cbl.Items) {
        item.Selected = Model.ProgLanguages.Contains((int)item.Value);
    }
};

Call the editor's GetSelectedValues method to get multiple selected items on the Controller side. To obtain Model fields from the corresponding editor, use a DevExpressEditorsBinder object.

public ActionResult Index([ModelBinder(typeof(DevExpressEditorsBinder))] MyModel model) {
    model.ProgLanguages = CheckBoxListExtension.GetSelectedValues<int>("ProgLanguagesUnbound");
    TempData["PostedModel"] = model;
    return RedirectToAction("Success");
}

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)