ASP.NET MVC , Razor and Validations!!

Just created a sample to showcase EF 4.0 Code First approach..it so happens that the app made to showcase uses the MVC 3.0 pattern with Razor implementation .

So why not highlight a few points there too.

  1. Goodbye <%=%> , hello @
    @Model.IdeaTitle +":"+@Model.Description+" :"+ @Model.SubmittedBy 

  1. Server tag commenting…
    @*@{
        ViewBag.Title = "Index";
    }*@

  2. ViewBag plus View
     public ActionResult Index()
    {
       IdeaContext context= new IdeaContext();
        var j = context.Ideas;
        ViewBag.Title = " Idea List";
        return View(j.ToList());
     }

@model IEnumerable<IdeaMVC.Models.IdeaModel>

<h2>@ViewBag.Title</h2>

4.   User Controls..

@Html.Partial("_DetailsPartialPage", Model)

5. Server side validation using Annotations (Server Side)

 [HttpPost]
 public ActionResult Create(IdeaModel  idea)
 {
   try
     {
        if (ModelState.IsValid)
         {...
         }
    }
}

6. Client Side Validatation

<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type ="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type ="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcValidation.js")" type ="text/javascript"></script>

image

7. Layout..

  <div id="main">
            @RenderBody()
            <div id="footer">
            </div>
   </div>

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

Small snippets to showcase changes…There are of course many more changes/improvements but then the intention was to showcase Code First Entity Framework…a Full Fledged MVC 3.0 coming up soon..

Incase you want the full app for download (this plus Code First EF) do drop me a mail..

Cennest

Advertisements

Migrating ASP.Net MVC 1 to ASP.Net MVC 2

With release of ASP.NET MVC 2, are you planning to migrate your ASP.Net MVC 1 applications. Here are few links which would help you to migrate

  • Eilon Lipton has created migration tool for migrating ASP.NET MVC 1 solutions to ASP.Net MVC 2 solution over here
  • To manually upgrade project  one can find instructions at www.asp.net over here

This will help you to migrate solution, but it would not leverage features of ASP.Net MVC 2. For that you will need to manually change your code.

Also after using this tool or instruction, it would be required to check if solution is able to build successfully and if building it with ASP.Net MVC 2 has lead to any logical bugs, since there are couple of breaking changes introduced in ASP.Net MVC 2

ASP.Net MVC 2 RTM Released

ASP.Net MVC 2 RTM has finally released and available on MSDN for download here

Brief on ASP.Net MVC 2 RTM

ASP.NET MVC 2 is a framework for developing highly testable and maintainable Web applications by leveraging the Model-View-Controller (MVC) pattern.

The framework encourages developers to maintain a clear separation of concerns among the responsibilities of the application – the UI logic using the view, user-input handling using the controller, and the domain logic using the model. ASP.NET MVC applications are easily testable using techniques such as test-driven development (TDD).

Comparison of ASP.Net MVC 2 RTM with ASP.Net MVC 1 RTM

ASP.Net MVC 2 RTM as compared to ASP.Net MVC 1 RTM has following additional features:

  • Support for Areas: Area feature in ASP.Net MVC 2 would allow complex application to be divided into modules.
  • Improved Security: JSONResult now supports only POST request by default.
  • Improved functionality:
    • Every property for model objects that use IDataErrorInfo to perform validation is validated, regardless of whether a new value was set
    • The UrlParmater.Optional property can be used to work around problems when binding to a model that contains an ID property when the property is absent in a form post
  • Templated Helpers: Feature from ASP.Net Dynamic Data Website in MVC for views.
  • New Validators
  • Support for binding binary data
  • Support for Asynchronous Controller Calls
  • and many more…….

I would be posting few more elaborate blog post on ASP.Net MVC 2 RTM in near future, keep watching…