Upgrading an ASP.NET MVC 1.0 Project to ASP.NET MVC 2

Upgrading an ASP.NET MVC 1.0 Project to ASP.NET MVC 2

To upgrade an existing ASP.NET MVC 1.0 application to version 2, follow these steps:

  1. Make a backup of the existing project.
  2. Open the project file in a text editor (the file with the .csproj or .vbproj file extension) and find the ProjectTypeGuid element. As the value of that element, replace the GUID {603c0e0b-db56-11dc-be95-000d561079b0} with {F85E285D-A4E0-4152-9332-AB1D724D3325}. When you are done, the value of that element should be as follows:

<ProjectTypeGuids>{F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

  1. In the Web application root folder, edit the Web.config file. Search for System.Web.Mvc, Version=1.0.0.0 and replace all instances with System.Web.Mvc, Version=2.0.0.0.
  2. Repeat the previous step for the Web.config file located in the Views folder.
  3. Open the project using Visual Studio, and in Solution Explorer, expand the References node. Delete the reference to System.Web.Mvc (which points to the version 1.0 assembly). Add a reference to System.Web.Mvc (v2.0.0.0).
  4. Add the following bindingRedirect element to the Web.config file in the application root under the configuraton section:

<runtime>

<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>

<dependentAssembly>

<assemblyIdentity name=”System.Web.Mvc”

publicKeyToken=”31bf3856ad364e35″/>

<bindingRedirect oldVersion=”1.0.0.0″ newVersion=”2.0.0.0″/>

</dependentAssembly>

</assemblyBinding>

</runtime>

  1. Create a new ASP.NET MVC 2 application. Copy the files from the Scripts folder of the new application into the Scripts folder of the existing application.

Compile the application and run it.


I Wan to share this post:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • kick.ie
  • Live
  • MyShare
  • IndianPad
  • Reddit
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • DotNetKicks
  • DZone
  • TwitThis

Asp.net MVC Dropdown selected value



How to get selected item in asp.net drop down list using asp.net mvc?

If you are struggling with how to show selected value in asp.net Drop down list using asp.net mvc then following code may be helpful.
Asp.net MVC Controller Code

///
/// Sets the drop down

private void setDropDown(Company company)
{
ICountryRepository countryRepository = new CountryRepository();
ViewData["Countries"] = new SelectList(countryRepository.ListAll(), "Id", "Title", company.CountryID);

}

I am passing following from my Controller to generate the HTML list for me.

ViewData["Countries"] = new SelectList(countryRepository.ListAll(), "Id", "Title",company.CountryID);

I was using  <%= Html.DropDownList(“Id”, (SelectList)ViewData["Countries"])%> in my view which then was generating following HTML

<select id="Id" name="Id"><option value="b3625530-5fed-46d4-ac0e-8a9b2d7b08bc">Pakistan</option>
<option value="42979373-1ab9-4659-8298-79952c612fe6">Saudi Arabia</option>
<option value="103800fd-5b0d-4793-aa01-4ee704970d8a">United Arab Emirates</option>
<option selected="selected" value="799dda4c-0907-4331-9366-3c98d2a19049">United Kingdom</option>
<option value="5705dcb4-dec7-4775-a09d-a21b06a8f91a">United States of America</option>
</select>

and i was unable to select the item in drop down list but as soon as i changed it to
<%= Html.DropDownList(“value”, (SelectList)ViewData["Countries"])%> it generated following HTML and I was able to get selected item in drop down list.

HTML Code generated on web page for the drop down list

 <select id="value" name="value"><option value="b3625530-5fed-46d4-ac0e-8a9b2d7b08bc">Pakistan</option>
<option value="42979373-1ab9-4659-8298-79952c612fe6">Saudi Arabia</option>
<option value="103800fd-5b0d-4793-aa01-4ee704970d8a">United Arab Emirates</option>
<option selected="selected" value="799dda4c-0907-4331-9366-3c98d2a19049">United Kingdom</option>
<option value="5705dcb4-dec7-4775-a09d-a21b06a8f91a">United States of America</option>
</select>


I Wan to share this post:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • kick.ie
  • Live
  • MyShare
  • IndianPad
  • Reddit
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • DotNetKicks
  • DZone
  • TwitThis