Help migrating asp.net mvc 1 to mvc 2 - asp.net-mvc

I just joined a team thats developing a asp.net mvc 1 application.
I only have visual studio 2010 installed which comes with mvc 2.
I ran the conversion wizard and now the app doesnt seem to compile
The error I get is
"Cannot apply indexing with [] to an
expression of type
'System.Web.Mvc.IValueProvider"
i get this error 5 times in different places of the app.
The line is
ModelState.SetModelValue(inputTagName, new ValueProviderResult(ValueProvider[inputTagName].AttemptedValue, file.FileName, System.Globalization.CultureInfo.CurrentCulture));
To be honest I've no clue on what its doing but my peers (using Mvc 1) dont have trouble compiling.
Please help.

This is one of the (few) breaking changes between MVC 1 and MVC 2. The ValueProvider has been completely redone to support multiple value providers and no longer has an index property. The short answer is to change this to use GetValue( inputTagName ). The longer (and better) answer is to change the code to use models for your action method inputs and not pull the data out of the value provider directly in your code. Rather, you rely on model binding to access the value provider and set the properties on your model.

Change ValueProvider[inputTagName].AttemptedValue to ValueProvider.GetValue(inputTagName).AttemptedValue.
Note that your entire team should be developing against the same version of ASP.Net MVC; otherwise; you'll run into lots of trouble.

Related

Converting ASP.NET WebForms project to MVC4 project

We have approximately 900 aspx pages website (webforms). We need to convert them into mvc4 application.
Problem is that when we convert it to mvc4 then it need to convert in to form of webapplication and when it convert in to webapplication then it create multiple designer file into my project. and it fire the error that
Error 5 Type 'Admin_Page_List_World' already defines a member called 'Page_Load' with the same parameter types
This happened because the Admin_Page_List_World class is a partial class and it is defined in multiple places.
If I remove the particular class then it fires the error partial directive is used in another place. There are multiple entry.
So, can anyone explain or suggest what I can do to resolve this issue?
Are you converting everything into MVC in one shot?I would suggest a iterative approach. Convert the project into MVC and make sure the .aspx routes are ignored. Then slowly change pages one by one. One good link below.
http://blog.falafel.com/integrating-aspnet-mvc-4-into-existing-web-forms-applications/

User of Razor on an MVC 2 application

I am new to MVC so I am asking this question,
I have visual studio 2010 version 4.0.30319 SP1 Rel already installed and currently we are using MVC2 . I have been asked to you MVC3 razor view engine. So in order to get that I am assuming, I need to install this
http://www.microsoft.com/web/gallery/install.aspx?appsxml=&appid=MVC3
My question is, can I start developing using MVC3 in my existing project which is currently in MVC2 ? I dont want to modify the existing code or upgrade to MVC3. Is it possible ?
Is there any other thing that I need to download and install. What are the changes that I need to make in my web.config file or any other file to make this MVC2 project run ?
Please help
This isnt something iv'e done before but the link below will make the appropriate referential changes in order to create razor view pages.
MVC 3 Conversion
However there was a link I found on that page in the comments provided by mpost dated july 15h 2011 to a exe conversion tool. Would be interested to see how much success, if any you get from it.
Razor view converter

How to display an ASP.net MVC project version in page?

In WinForms, I'd use Application.ProductVersion.
I've tried using System.Reflection.Assembly in various ways but can never get the version of just the MVC project.
Provided this code is explicitly in the MVC project (rather than in a helper assembly), you should be able to use System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(3), which returns the major, minor, and revision numbers. Otherwise you might want to use something like typeof(HomeController).Assembly.GetName().Version.ToString(3).

ASP.NET MVC for Ruby on Rails developers?

Long time lurker, first time poster. I'm a self-taught hacker that learned Ruby on Rails to start. At work I've been allowed to work on a web app--the only catch is I have to use ASP.NET. This technology choice is mandated, as much as I'd prefer to use Rails.
There's dozens of "Rails for .NET/PHP/Java Developers" books and blog posts but I haven't found any going the opposite direction, from Rails to .NET.
Could someone please give me an overview of how a typical Rails app would translate over to ASP.NET MVC? I'll research the details of the IDE, C#/VBscript, etc. But what are the possible equivalents to:
Generators
Gems/Plugins
Databases
Migrations
Routes
Models (ORMs)
Controllers (InheritedResources)
Views (layouts, templates, partials)
Rails Console
Test Units/Specs
etc. anything else I'm forgetting
I assume a lot of the Rails niceties I take for granted like route-based helper methods, and simple macro association declarations will not be possible. :(
Thank you so much!
I think what you'll find in the .Net world is that you have a lot of choices to make. Rails is nice because it provides all of that stuff in one place, but developing for .Net you'll have to piece together a solution of your own.
Generators - There are various code generation facilities, but each one is for a different piece. Eg, you can get MyGeneration that will generate code based on a database.
Gems/Plugins - No uniting system for this; Components can be found on the web and you would download either the source or the .dll, then you would add a reference in your project to the assembly (.dll).
Databases - you can connect to pretty much anything; You'll probably find the most guidance for an MS SQL Server.
Migrations - I don't know of a direct method for this in the .net world; I usually write SQL code in SQL and run scripts on the server manually as part of deployment.
Routes - ASP.Net MVC includes routes, look in the global.asax.cs file that gets generated when you create a project for example.
Models (ORMs) - ORMs for .Net are all over the place. Included as part of .Net are things like Linq-to-sql and the Entity Framework. Outside of MS you can find many, but I'd probably recommend NHibernate.
Controllers - Built in to .Net MVC; You get to write the code.
Views - Built in to .Net MVC; Once again you get to write them. MasterPages allow you to get the same general layout on all your pages(including common header/footer, etc), Web Controls (.ascx files) allow you to do a partial view.
Rails Console - I don't know exactly what this provides (I'm a .net developer interested in learning Rails, but haven't spent much time yet); Visual Studio lets you debug applications, step through code, etc. I don't think there are any consoles available to test code outside of just writing the code, compiling, and running it.
Test Units/Specs - There are a few test frameworks for .Net (MS has a framework included, NUnit is one alternative). For specs and such, probably google around for Behavior Driven Design and see what exists.
There are a couple of .NET ports of RoR migrations. I have used migratordotnet and FluentMigrator. Both work as expected but I prefer FluentMigrator. It is more full-featured (e.g. can create indexes) and I like the fluent style.
LINQPad is your equivalent to Rails Console.. see here:
https://stackoverflow.com/a/9403457/1029644
You should download Visual Studio 2008 Express, and download ASP.NET MVC 1.0 (I wouldn't download ASP.NET MVC 2.0 yet because it's only in RC. Wait until it hits 2.0 final).
You can also check out the Nerddinner walkthrough. It's very helpful when learning ASP.NET MVC.
Generators
Do you mean code generators? Ew.
Gems/Plugins
If you want functionality, you can either build it or see if a JQuery plugin exists for it.
Databases
The Database is accessed through your model.
Migrations
?
Routes
Routing is handled by the framework, and you can add routes in the Global.asax.cs file.
Models (ORMs)
Models are indeed still called 'Models', and in ASP.NET MVC, if you use LINQ-To-SQL, the model is generated for you when you drag your database tables in. You can use the Repository pattern to access the database model.
Controllers (InheritedResources)
Controllers are still called controllers.
Views (layouts, templates, partials)
There are different types of View Engines, but the one provided with ASP.NET MVC should do well at first.
Rails Console
I'm guessing you mean the IDE/Debugger? You can build and debug an ASP.NET MVC app inside of Visual Studio.
Test Units/Specs
You can use NUnit, or you can use MSUnit. MSUnit is already integrated with Visual Studio, but NUnit can be.

How do you get the area of the current request when using MVC 2 RC?

I was using MVC 1.0 RTM, and the Haack solution for Areas
I just recently moved to MVC2 RC and I'm using single project areas with my controllers in separate assemblies. My problem is that in the MVC 1 solution I ALWAYS had "area" in my RouteData.Values collection, in MVC2 RC it doesn't exist. Do you know how to get this in MVC2 RC?
Thanks in advance!
This is kept in a DataToken for the route. Namely, route.DataTokens["area"]. Look at AreaHelpers.cs in the MVC source for details.
By the way, when you ask a question like this, you should show the code you're using which is not working. It makes it much easier to supply an answer. Right now, I don't know if you've already tried the method above, but are making an error with it, or if you haven't discovered this yet.

Resources