Model binding comma separated query string parameter

Here’s my improved version of Nathan Taylor’s solution used in archil’s answer. Nathan’s binder could only bind sub-properties of complex models, while mine can also bind individual controller arguments. My binder also gives you correct handling of empty parameters, by returning an actual empty instance of your array or IEnumerable. To wire this up, you … Read more

.Net Mvc 3 Trigger (other than submit button) Unobtrusive Validation

$(‘form’).valid() should work. Let’s exemplify. Model: public class MyViewModel { [Required] public string Foo { get; set; } } Controller: public class HomeController : Controller { public ActionResult Index() { return View(new MyViewModel()); } } View: @model MyViewModel <script src=”https://stackoverflow.com/questions/6301492/@Url.Content(“~/Scripts/jquery.validate.js”)” type=”text/javascript”></script> <script src=”https://stackoverflow.com/questions/6301492/@Url.Content(“~/Scripts/jquery.validate.unobtrusive.js”)” type=”text/javascript”></script> @using (Html.BeginForm()) { @Html.LabelFor(x => x.Foo) @Html.EditorFor(x => x.Foo) @Html.ValidationMessageFor(x => … Read more

Currency Formatting MVC

You could decorate your GoalAmount view model property with the [DisplayFormat] attribute: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = “{0:c}”)] public decimal GoalAmount { get; set; } and in the view simply: @Html.EditorFor(model => model.Project.GoalAmount) The second argument of the EditorFor helper doesn’t do at all what you think it does. It allows you to pass additional … Read more

Parser Error: Server Error in ‘/’ Application

Right-click your Global.asax file and click View Markup. You will see the attribute Inherits=”nadeem.MvcApplication”. This means that your Global.asax file is trying to inherit from the type nadeem.MvcApplication. Now double click your Global.asax file and see what the class name specified in your Global.asax.cs file is. It should look something like this: namespace nadeem { … Read more

@Html.BeginForm Displaying “System.Web.Mvc.Html.MvcForm” on Page

The recommended way to generate a form is the following: <div id=”deletestatusupdate”> @if (update.User.UserName.Equals(User.Identity.Name, StringComparison.OrdinalIgnoreCase)) { using(Html.BeginForm(“deleteupdate”, “home”)) { @Html.Hidden(“returnUrl”, Request.Url.ToString()) <button name=”id” value=”@update.StatusUpdateId”>Delete</button> } } </div> Alternatively you could do this: <div id=”deletestatusupdate”> @if (update.User.UserName.Equals(User.Identity.Name, StringComparison.OrdinalIgnoreCase)) { Html.BeginForm(“deleteupdate”, “home”); @Html.Hidden(“returnUrl”, Request.Url.ToString()) <button name=”id” value=”@update.StatusUpdateId”>Delete</button> Html.EndForm(); } </div> The reason why your original approach did … Read more