Showing posts with label MVC 3. Show all posts
Showing posts with label MVC 3. Show all posts

Thursday, June 23, 2011

MVC 3 enable jQuery IntelliSense support

In the Razor view engine, there is no central place to add the reference to the vsdoc file,
instead you need to add this code line to each view separately to enable the IntelliSense
support for jQuery.
 

<!DOCTYPE html>
<
html>
<
head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript">
</
script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript">
</
script>
</head>
<body>
@RenderBody()

/***** Add this line to your razor page to  enable Visual Studio's IntelliSense support for jQuery *****/

@
if (false) { <script src="~/Scripts/jquery-1.5.1-vsdoc.js" type="text/javascript">
</script> }
//The if-statement prevents the script tag from being rendered into the html 
//source code.

<script type="text/javascript" >
// jquery code here... now it will show intellisence for the jQuery
</script>
</
body>
</
html>

In case of asp.net pages.. add the following code..

<%
if (false)
 
      { %> 
        <script src="~/Scripts/jquery-1.5.1-vsdoc.js" 
                type="text/javascript"></script> 
    <%} %>

Thursday, May 26, 2011

Grid Control in MVC 3.0

It is the code of the StoreController which display List of albums in the Genre.
To Display these items in the grid pass the to the view as list of items type of
Album. Here i am using Linq to SQL for getting data from the tables.

//
// GET: /Store/Browse?genre=Disco

public ActionResult Browse(string genre)
{
//var genreModel = new Genre { Name = genre };
//var albums = from m in storeDB.Albums
// where m.Genre.Name == genre
// select m;

var albums = from m in storeDB.Albums
            
join v in storeDB.Genres
            
on m.GenreId equals v.GenreId
             
where v.Name == genre
            
select m;

var albumList = albums.ToList<Album>();
//return view with list of albums to the View.
return View(albumList);
}

It is the Code at the View of this Method. where i have specified the
Model type in the firld line and after that created the grid and
assigned the data ( list of albums) the grid.
then the html is fetched at the page to display on the view..

@model IEnumerable< MvcMusicStore.Album>
@{
ViewBag.Title =
"Browse";
var data = Model;
var grid = new WebGrid(data);
}
<h2>Browsing Genre: @Model.Count()</h2>
<
div>
@grid.GetHtml()
</div>
@*<ul>
@foreach (var album in Model)
{
//<li><a href="/Store/Browse?genre=@genre.Name">@genre.Name</a></li>
//<li>@Html.ActionLink(genre.Name,"Browse",new {genre=genre.Name})</li>
<li>@album.Title</li>
}
</ul>
*@