开发者

How to handle lookups?

开发者 https://www.devze.com 2023-01-20 16:55 出处:网络
When I need to use a lookup I usually include the ID property in the view model class so I can use it this way in the corresponding view

When I need to use a lookup I usually include the ID property in the view model class so I can use it this way in the corresponding view

<%= Html.LabelFor( model => model.LookupTableID )%>
<br />
<%= Html.DropDownListFor(model => model.LookupTableID, Model.LookuptableList, new {}) %>

having Model.LookuptableList as a property in the Model itself like this:

public IEnumerable<SelectListItem> LookuptableList {
    get {
        return GetLookuptableList().Select(
            t => new SelectListItem { Text = t.Description, Value = t.LookupTableID.ToString() } );
    }
}

But I am not sure that this i开发者_开发知识库s a good way to handle this because of the function GetLookuptableList() inside the view model class.

is there a better/cleaner way to do this?


You are including the entire look up table with every instance of the view model. A little overkill. I usually create a static utility class with the look up table that returns the SelectListItem.

0

精彩评论

暂无评论...
验证码 换一张
取 消