Razor HtmlHelper Extensions (or other namespaces for views) Not Found

Since the Beta, Razor uses a different config section for globally defining namespace imports. In your Views\Web.config file you should add the following: <configSections> <sectionGroup name=”system.web.webPages.razor” type=”System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″> <section name=”host” type=”System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” /> <section name=”pages” type=”System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ requirePermission=”false” /> </sectionGroup> </configSections> <system.web.webPages.razor> <host factoryType=”System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, … Read more

Can the ViewBag name be the same as the Model property name in a DropDownList?

You should not use the same name for the model property and the ViewBag property (and ideally you should not be using ViewBag at all, but rather a view model with a IEnumerable<SelectListItem> property). When using @Html.DropDownListFor(m => m.CustomerId, ….) the first “Please Select” option will always be selected even if the value of the … Read more

HTML.ActionLink method

I think what you want is this: ASP.NET MVC1 Html.ActionLink(article.Title, “Login”, // <– Controller Name. “Item”, // <– ActionMethod new { id = article.ArticleID }, // <– Route arguments. null // <– htmlArguments .. which are none. You need this value // otherwise you call the WRONG method … // (refer to comments, below). ) … Read more

MVC5 – How to set “selectedValue” in DropDownListFor Html helper

When you use the DropDownListFor() (or DropDownList()) method to bind to a model property, its the value of the property that sets the selected option. Internally, the methods generate their own IEnumerable<SelectListItem> and set the Selected property based on the value of the property, and therefore setting the Selected property in your code is ignored. … Read more