ASP.NET MVC , Razor and Validations!!

Just created a sample to showcase EF 4.0 Code First 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>


4.   User Controls..

@Html.Partial("_DetailsPartialPage", Model)

5. Server side validation using Annotations (Server Side)

 public ActionResult Create(IdeaModel  idea)
        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>


7. Layout..

  <div id="main">
            <div id="footer">

    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..


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>