Code snippets for ASP.NET MVC2 in VS 2010

Posted by rajbk on ASP.net Weblogs See other posts from ASP.net Weblogs or by rajbk
Published on Mon, 19 Apr 2010 02:23:27 GMT Indexed on 2010/04/19 2:34 UTC
Read the original article Hit count: 845

Filed under:
|
|
|

VS 2010 comes with ready made snippets which helps you save time while coding.

You insert a snippet by typing the name of the code snippet and hitting the Tab key twice. You can also use the following method if you wish to see a listing of snippets available.

  • Press Ctrl + K, Ctrl + X
    image
    Select ASP.NET MVC2 with the arrow keys and hit enter to see a list of snippets available.
    image 


The MVC related snippets you get out of the box (for C#) are listed below:

HTML

  • actionlink
    Markup snippet for an ASP.NET MVC action link helper
    <%= Html.ActionLink("linktext", "actionname") %>
     
  • beginformajaxcs
    Markup snippet for an ASP.NET MVC AJAX-enabled form helper in C#
    <% using (Ajax.BeginForm("actionname", new AjaxOptions {UpdateTargetId= "elementid" })) { %>
    <% } %>
     
  • beginformcs
    Markup snippet for an ASP.NET MVC form helper in C#
    <% using (Html.BeginForm()) { %>
    <% } %>
     
  • displayforcs
    Markup snippet for an ASP.NET MVC templated helper.
    <%= Html.DisplayFor(x => x.Property) %>
     
  • editorforcs
    Markup snippet for an ASP.NET MVC templated helper.
    <%= Html.EditorFor(x => x.Property) %>
     
  • foreachcs
    Markup snippet for an ASP.NET MVC foreach statement in C#
    <% foreach (var item in collection) { %>
    <% } %>
     
  • ifcs
    Markup snippet for a code-nugget if else statement in C#
    <% if (true) { %>
    <% } %>
     
  • ifelsecs
    Markup snippet for a code-nugget if else statement in C#
    <% if (true) { %>
    <% } else { %>
    <% } %>
     
  • renderpartialcs
    Markup snippet for an ASP.NET MVC partial view rendering in C#
    <% Html.RenderPartial("viewname"); %>
     
  • textboxmvc
    Markup snippet for an ASP.NET MVC textbox helper
    <%= Html.TextBox("name") %>
     
  • validationsummarymvc
    Markup snippet for an ASP.NET MVC validation summary helper
    <%
    = Html.ValidationSummary() %>

CS

  • mvcaction
    Code snippet for an action.
    public ActionResult Action()
    {
        return View();
    }
     
  • mvcpostaction
    Code snippet for an action via http post.
    [HttpPost]

    public ActionResult Action()
    {
        return View();
    }
     

Enjoy!

© ASP.net Weblogs or respective owner

Related posts about ASP.NET

Related posts about Visual Studio