Separating the service layer from the validation layer

Short answer: You are validating the wrong thing. Very long answer: You are trying to validate a PurchaseOrder but that is an implementation detail. Instead what you should validate is the operation itself, in this case the partNumber and supplierName parameters. Validating those two parameters by themselves would be awkward, but this is caused by … Read more

ASP.NET MVC Url Route supporting (dot)

Add a UrlRoutingHandler to the web.config. This requires your url to be a bit more specific however (f.e. /Users/john.lee). This forces every url starting with /Users to be treated as a MVC url: <system.webServer> <handlers> <add name=”UrlRoutingHandler” type=”System.Web.Routing.UrlRoutingHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” path=”/Users/*” verb=”GET”/> </handlers> </system.webServer>

The difference between Html.Action and Html.RenderAction

Try: @{Html.RenderAction(“Breadcrumb”, “Navigation”, new {SeoUrl = Model.CarlineBucket.SEOURLName});} @Html.RenderAction() generates a write call to output something on the page and in your case you are not doing so because RenderAction renders the result directly to the Response. Instead of @Html.RenderAction() Use @{Html.RenderAction();}

Getting Multiple Selected Values in Html.DropDownlistFor

Use a ListBoxFor instead of DropDownListFor: @Html.ListBoxFor(m => m.branch, CommonMethod.getBranch(“”, Model.branch), “–Select–“) @Html.ListBoxFor(m => m.division, CommonMethod.getDivision(Model.branch, Model.division), “–Select–“) The branch and division properties must obviously be collections that will contain the selected values. And a full example of the proper way to build a multiple select dropdown using a view model: public class MyViewModel { … Read more

How do I access ViewBag from JS

if you are using razor engine template then do the following in your view write : <script> var myJsVariable=”@ViewBag.MyVariable” </script> UPDATE: A more appropriate approach is to define a set of configuration on the master layout for example, base url, facebook API Key, Amazon S3 base URL, etc …“` <head> <script> var AppConfig = @Html.Raw(Json.Encode(new … Read more

Change Layout(Master Page) of view in ASP.NET MVC without recreate it

In MVC3 you have _ViewStart.cshtml that stores all pages’ Layout; you can change this element to change all pages’ Layout or you can add new Layout element in top of target view pages in @{} block like the following to change the layout of the specific page: @{ Layout = “~/Views/Shared/_newLayout.cshtml”; ViewBag.Title = “Index”; }