четверг, 14 марта 2013 г.

Removing implicit validation

Assume that we have a model
public class Order
{
    [DisplayName("Purpose")]
    public string purpose { get; set; }

    [DisplayName("Tasks")]
    public string tasks { get; set; }
}
As we can see none of these fields have "Reguired" attribute. Any when you look at HTML source code in you browser you could find: data-val-required="The Purposefield is required." To remove this attribute just add the line into Application_Start method in Global.asax.cs file:
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;

Asp.net MVC. How to get rid of /home/ in url

Assume we want to have an url to the Contacts page like mysite/Contacts instead of mysite/Home/Contacts

First of all open RouteConfig.cs under App_Start folder.

      public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute("HomeRemover", "{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }); // add this
            routes.MapRoute("Home", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
        }
That's all.

пятница, 4 января 2013 г.

Where are MVVM light project templates?

Recently I came across with a problem. The problem was that after installing galasoft mvvm toolkit I didn't find any project templates in my VS2010 pro.
To fix it we need to go to YOUR_DISK_DRIVE:\My documents\Expression\Blend 4\ProjectTemplates\CSharp and copy Mvvm folder into C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp.

Then run from command line devenv /installvstemplates.
Start Visual Studio and have fun :)