开发者

Modal State with ASP.NET MVC with SelectLists?

开发者 https://www.devze.com 2022-12-18 11:22 出处:网络
I have read various articles about the modal state that is used in the ASP.NET MVC. I have read this article link text from Scott Gu. I have some code in my controllers that are hitting the database e

I have read various articles about the modal state that is used in the ASP.NET MVC. I have read this article link text from Scott Gu. I have some code in my controllers that are hitting the database every time a select list is need to display an error. Is there any way to have the modal state save the lists contents? Or maybe cache the lists?

// controller code 
// re display the er开发者_运维技巧ror do to a business rule violation
_ratesViewData.FSCCOde = getFscCode(_rateService.GetFscCode());

 // controller code 
 private SelectList getFscCode(IEnumerable items, object selectedValue)
 {
    return new SelectList(items, "FscID", "FscCode", selectedValue);
 }

// ASP.NET MVC control code   
// ASP.NET MVC control code  
// ASP.NET MVC control code  
Fuel Surcharge Code
<%=Html.DropDownList( "FscCode", "No Fuel Surcharge")%


First, re-displaying a view because of an error is typically an uncommon operation. I would want to spend my energy optimizing more common operations, like displaying the view in the first place. Second, given that the typical drop-down combo box has, at most, a few dozen items, I would wonder if there's not a deeper problem if this is actually an optimization issue because of database load. Third, caching the lists is fine if you determine that this is actually a performance issue, but I wouldn't optimize anything until you are positive it is a problem.

0

精彩评论

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