Monday, 17 January 2011 09:51 by
mha
I’m in the process of re-writing www.aspnethotel.dk to use ASP.NET MVC 3 and are planning to use the new view engine (“Razor”). For more info about this, take a look at http://www.asp.net/mvc/mvc3
c9311857-2ba5-411d-988d-a8be83e7fa6a|1|5.0
Wednesday, 10 February 2010 07:49 by
mha
Kazi Manzur Rashid has put together a blog post (in 2 parts) about ASP.NET MVC Best Practices which is worth reading if you’re working with ASP.NET MVC.
ASP.NET MVC Best Practices (Part 1)
ASP.NET MVC Best Practices (Part 2)
23f0763d-d0f5-4848-9362-a238b53fdfe7|0|.0
Tuesday, 9 February 2010 14:51 by
mha
Jeffrey Palermo has an inspiring article about templating and (why not) to use .ascx aka UserControls in ASP.NET MVC – I’ll definitely be using this approach:
http://jeffreypalermo.com/blog/asp-net-mvc-and-the-templated-partial-view-death-to-ascx/
74029603-362e-4648-bd4f-22369eead219|2|3.0
Tuesday, 9 February 2010 12:51 by
mha
If you’re using ASP.NET MVC, you’re probably also using jQuery and hence would like to have IntelliSense support in your ViewPages. According to Scott Gu all you need to do is to make sure you’re having the “-vsdoc.js” file in your script folder (e.g. “jquery-1.3.2-vsdoc.js”) and VS2008 (with the patch installed!) will find this file and jQuery IntelliSense works – however as it turns out if you’re using a path which starts with “/” (as you should!) VS2008 is unable locate the “-vsdoc.js” file and you will not have any jQuery IntelliSense support.
So there’s a little more to know about how exactly jQuery IntelliSense actually works in order to make this work correctly (not to mention IntelliSense support in .ascx files). Luckily Jouni Heikniemi have written a great article about this – check it out:
http://www.heikniemi.net/hardcoded/2009/08/jquery-intellisense-on-asp-net-mvc/
da7c01c4-68c2-4f1a-b709-a15164498e55|0|.0
Sunday, 17 January 2010 15:16 by
mha
A small example of where LINQ Projection might come in handy is when you’re working with MVC. In the below example LINQ Projection is used to transform a enumeration of EmployeeCategory instances into an enumeration of SelectListItem instances:
var rep = new mhaRepository();
var person = rep.GetPersonByID(id);
ViewData["EmployeeCategories"] = from c in rep.EmployeeCategories
select new SelectListItem
{
Text = c.Name,
Value = c.ID.ToString(),
Selected = (c.ID == person.CategoryID)
};
In the View all that is needed to render the DropDownList is this:
<%= Html.DropDownList("EmployeeCategories") %>
e0e1a982-9c41-4976-ae2a-27e4bb735dc2|0|.0
Wednesday, 30 December 2009 08:12 by
mha
If you’re using ASP.NET MVC and are using the ViewData collection you might want to familiar yourself with the ?? operator.
The ?? operator is called the null-coalescing operator and is used to define a default value for a nullable value types as well as reference types. It returns the left-hand operand if it is not null; otherwise it returns the right operand.
Knowing this we can use the below syntax to e.g. display the title of a page in the browser with a value from ViewData and if this is null instead display a default value.
<%= ViewData["title"] ?? "Home Page" %>
MSDN has more info about the ?? operator.
4b4ef715-d44b-4836-8dcd-7464f7af18d1|0|.0