Skip to main content

Posts

Showing posts from March, 2015

Enable jQuery Intellisense support to MVC3 Razor

jquery intellisense support helps a lot while programming with jQuery. By default Visual Studio doesn't provide us the jQuery intellisense support. We can enable the jQuery intellisense support in Visual Studio with MVC Razor by adding vsdoc.js file to your view like as : @if (false) { <script src = "~/Scripts/jquery-1.7.1-vsdoc.js" type = "text/javascript" ></script> } The above if-statement prevents the rendering of script tag into the html source code and it used only by the Visual Studio for jQuery intellisense support. To check jQuery intellisense type the $ or $( between your $(document).ready(function() function and you can see the intellisense as shown in fig.   Note In MVC Razor, there is no central place to add the reference to the vsdoc.js file. We need to add this code line to each every view separately to enable the IntelliSense support for jQuery.

Inline CSS and Styles with Html Helpers in MVC3 Razor

  Asp.net, we can custom the look and feel of a server controls by using CSS class,id and inline css. Similarly, we can change the style of Html Helpers in MVC razor. I this article, I am going to explain how can change the style of a Html Helpers by using CSS. CSS Class . inputclass { width : 100px ; height : 25px ; } Apply CSS Class to Html Helpers Suppose above css class is defined in the external style sheet. Now you want to apply this class to html helpers then we need to add class name by using @class like as : @Html . TextBox ( "Name" , new { @class = "inputclass" }) @Html . TextBoxFor ( model => model . Name , new { @class = "inputclass" }) Apply Inline CSS to Html Helpers We can also add inline css to html helpers by using style like as : @Html . TextBoxFor ( model => model . Name , new { style = "width:100px;height:25px" }) @Html . TextBox ( "Name" , new { style = "

MVC Data Annotations for Model Validation

MVC Data Annotations for Model Validation   Data validation is a key aspect for developing web application. In Asp.net MVC, we can easily apply validation to web application by using Data Annotation attribute classes to model class. Data Annotation attribute classes are present in System.ComponentModel.DataAnnotations namespace and are availlable to Asp.net projects like Asp.net web application & website, Asp.net MVC, Web forms and also to Entity framework orm models. Data Annotations help us to define the rules to the model classes or properties for data validation and displaying suitable messages to end users. Data Annotation Validator Attributes DataType Specify the datatype of a property DisplayName specify the display name for a property. DisplayFormat specify the display format for a property like different format for Date proerty. Required Specify a property as required. ReqularExpression validate the value of a property by specified reg