asp.net mvc 2 - Basic HTML.DropDownListFor -
i have viewmodel defined as
public class linkvm { public al.common.content.object.pageindex[] pages{ get; set; } public string spageid { get; set; } } in strogly typed form using
<%html.dropdownlistfor(n => n.pages, new selectlist(model.pages, "pageid", "shortname", model.spageid ));%>
i compile error on selectlist(model.pages, portion says 'model' conflicts declaration 'system.web.mvc.viewpage.model'
there chunk of basic knowledge missing - can enlighten me please
thanks
it should be:
<%= html.dropdownlistfor( n => n.spageid, new selectlist(model.pages, "pageid", "shortname") ) %> also make sure view typed linkvm class (the @page directive @ top):
<%@ page language="c#" masterpagefile="~/views/shared/site.master" inherits="system.web.mvc.viewpage<al.mgrsite.viewmodel.content.linkvm>" %> also controller action rendered view needs pass correct model:
public actionresult index() { var model = new linkvm { // todo: fetch repository pages = new[] { new pageindex { pageid = "1", shortname = "name 1" }, new pageindex { pageid = "2", shortname = "name 2" }, new pageindex { pageid = "3", shortname = "name 3" }, } }; return view(model); } also convention in c# have class name , property names start capital letter.
Comments
Post a Comment