WebForm project to MVC - missing context menu items - asp.net

I have a significant webform project that needs MVC4 integrated into it. MVC controllers etc.. are working fine. However i am not getting the MVC type context menu items e.g. add view when right click a controller method (see below - this is the add view that I want to see. It is missing from my project).
I have tried creating a blank MVC project then swapping out the web form csproj file for this and readding in all the webform elements but it broke the site in all manner of ways that i don't have time to resolve. I really don't want to go down this rabbit hole in any case - i suspect it's the wrong approach.
I have tried adding in (what i believe to be) the correct projecttype guid into the csprojj file by editing with a text editor i.e.
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};
{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
becomes
<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};
{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
but i still do not get the correct context menu items.
Can anyone tell me what I am missing?
Many Thanks for all help
Edit
This link gives an example for MVC3 and gives an idea of what I am trying to achieve. But the project type guid crashes the site (because it is MVC3) and my own efforts aren't working
http://www.britishdeveloper.co.uk/2011/05/convert-web-forms-mvc3-how-to.html
Further details i think are probably irrelevant
The project is an install of EPiServer Relate+ 7. A new site is starting from this but the majority of the site itself will be MVC (i hope). But we will use the re-existing web form elements for community type pages. There is no time or budget to convert these.
I don't think this is relevant to the solution. I think the problem is generic rather than particular to EPiServer.

Embarrassing!!!
I nearly got this right. I just needed to restart Visual Studio when I changed the project type Guid
So - the project type Guid for MVC4 is
{E3E379DF-F4C6-4180-9B81-6769533ABE47};
and the full element is
<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};
{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
BUT - don't forget to restart Visual Studio (Doh!!!)
I'll keep this question up in case others have got the same problem
Thanks for everyone's time

Related

references for text boxes and other form controls in asp.net

I had a web application in visual studio and wanted to work on it.So i just copied all the project folders into an empty web application so i could work.But i am getting lost of errors related to references.
I added all the dlls in the bin folder into the references. Some of the errors reduced but now i am getting errors for all text boxes, drop down boxes i.e all form controls saying the name "" does not exist in the current context when i build the solution.
I tried adding system.windows.form to the reference folder but still its giving the same errors.Is is regarding references or something else? What is suppose to be done?
It mean they are not appearing in the designer as you coped them. You have to delete the controls and add them so that they can appear in the designer too
Hope this helps

ASP.Net - Transition from Visual Studio 2003 to Visual Studio 2010

we are in process of switching our ASP.Net development from Visual Studio 2003 and .Net 1.1 to Visual Studio 2010 and .Net 3.5. So far, we successfully migrated our back end code and after some fight the ASP.Net front end code too. While the work on the back end code resumed with usual productivity, working on the ASP.Net front end code is massively hampered because of following issues:
The Visual Studio 2010 Web Designer crashes frequently (e. g. after using the "Undo" function) - we are used to the stability problems of Visual Studio 2003 Web Designer when working with large web forms, but the new Web Designer crashes frequently even with trivial web forms. Is there anything to make the thing stable? ServicePack 1 brought no help.
When adding new controls to a webform in the web designer, the declaration of the new control will never automatically propagate to the code behind page in the migrated web form. New web forms created from scratch seem to work ok. The migrated web forms maintain the old file structure (aspx, aspx.cs and aspx.resx), while the new web forms get a new file structure (aspx, aspx.cs and aspx.designer.cs. Recreating all the existing web forms manually to get the new file structure would be a very painful operation. Is there a way to make the old decent working propagation of controls' declaration to code behind file work in Visual Studio 2010 too?
(Currently our biggest problem): when designing a web form, we basically put the textboxes, labels, buttons etc. in a div with ms_positioning="GridLayout". We define absolute coordinates for every control in the div. This doesnot seem to work properly in Visual Studio 2010. With a lot of effort we can somehow continue using this approach, but adding a new button or textbox to a web form means massive effort now. Without paying really much attention it can even result in overwritig of the css-classes-file (the Web Designer sometimes decides to write the coordinates not in the aspx file but in the css file). I read recently that using absolute coordinates to position stuff on a web page is a very bad and deprecated approach. I tend to believe it seeing how gruesome it has to be done in the new Visual Studio. But what is the correct way to create winforms-like web forms rapidly? (With rapidly I mean simple drag-drop-point-click way of designing stuff).
Thanks in advance for any help.
Best Regards
Erich Horak
I'll try to tackle this issue by issue:
Designer
Unfortunately, the new designer in Visual Studio 2010 has been plagued with issues. With 2010, the editor was completely revamped with WPF, which was supposed to make it faster, but thus far has seemed inferior to the previous editors. There are some improvements, but if I had an option to choose I would stick with the old editor, at least until the issues are worked out with the new one. It may not be any consolation, but you are not the only one feeling that pain.
Adding controls/new page file structure
Again, this is another situation where migration will prove painful. If I were to suggest an approach, I would copy paste the markup into newly created forms (created w/ VS 2010). The designer.cs file should register the controls. You might run into issues with event handler mappings, but hopefully it won't get in the way of the designer.cs file registering the controls. I know this is a painful prospect, but you have to keep in mind that you're moving up several versions.
Designer view & absolute positioning
While you're migrating the system, you might want to set the default view to source-view, so you can paste the HTML onto the page. You can do this by going to Tools > Options > HTML Designer > General. Honestly, in my opinion, the designer is really flaky and should be avoided. The HTML it produces really is horrible.
Using absolute coordinates to position elements on a page is a deprecated approach for sure, but if your goal at this point is to get your migration working, then don't worry about it for now. Eventually, it would be a good idea to refactor your HTML and CSS to use more modern techniques, but if the current code-base is browser-compatible, then leave it for now.
It may not seem like it at first, but if you can move away from the designer and use the source view, you won't regret it. It does take a little more time at first, but having control over the markup will end up saving you a lot of time in the long run. If the designer is allowed to run rampant throughout the system, it will screw things up. By using the source view, you have full control over everything that's happening, which will become a huge advantage. By leveraging new features like master pages, you can move just as quickly in the source-code view as in the designer view of 1.1. I started out with the designer-view myself in 1.1, but after switching to the source-view, I never looked back again. You really do make up the productivity in other ways.
I wish I could give you a "do this and everything will snap into place" kind of answer, but I think you're in for a painful conversion process. The good news is, once it's done you can start utilizing all of the new features that have come around in the past 8 years. ;)
I see no quick, drag & drop way of doing this. Things like GridLayout are deprecated; much easier in the long run to port the forms manually, cleaning up the markup as you go and using the code view of the forms instead of the design view. Also an opportunity to write clean, separate CSS rather than inline styles.
Post 1.1, you do not need to declare the form elements in the code-behind - the new partial classes obviate the need for that. So this is just one more thing that is different. I am actually working on a similar project right now; I availed of the new master classes which meant changing quite a bit anyway.
My honest advice is to suck it up and move on :)
I asked a similar question here:
Visual Studio Multi-Project Solution Options

Many ascx-to-one ascx.cs bug in VS2008

I'm developing second language support for the site. So I made duplicate .ascx and .aspx files for existing ascx.cs and aspx.cs
Most of the time everything works fine.. but suddenly I'm getting:
Type 'ctrl_xxx' exists both in 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\d072cc72\b9d5698b\App_Web_xdmblegv.dll', and in 'c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\d072cc72\b9d5698b\App_Web_gkptrzo2.dll' (translated from russian)
ctrl_xxx ctrl = (ctrl_xxx) LoadControl("xxx.ascx");
I have few such strings of code... and same error occurs with one of them. But WITHOUT any changes from me with those files. To fix thaat bug for some time I need to delete solution and website folder and reget them from SS. Maybe there is an issue with solution? Solution was converted from vs2005.
You shouldn't localize an asp.net site by duplicating pages or controls. You use, for example, language specific resource files that are referenced in the one page or control. Have a look at this for a start on how to localize asp.net websites.
I agree with #Joe R, copying code is not a good way to localize. You may feel like you have gone too far down this road to change your approach, but in the long run you will be much happier and more productive with a different solution.
At the minimum I would switch to a different approach for the rest of the localization, finish the project, and then go back later and convert what you have already done to the new method.
Take a look at the following:
Globalization and localization
demystified in ASP.NET 2.0
How
do you localize a database driven
website
If you need a quick fix for your problem, you'll need to give new names to all of the pages and controls you copied. The error comes from having two user controls with the same name (just like it says).
However, everyone else is correct in that you are going about this the wrong way. What happens when you need to change some code? It will cause extra maintenance because you need to make changes in two places. More than likely, you will forget one, and you'll end up wasting a lot of time. If you invest in using language resource files now, you'll save on headaches later. And, I'm not even mentioning the possibility of needing to add an additional language down the road.
Edit
Try the following if you still don't want to use language resource files.
Put the non-language specific code into a separate .cs file. Make sure it inherits from System.Web.UI.UserControl
In ASCX 1, make sure its ascx.cs class inherits from your class you created in step 1.
In ASCX 2, make sure its ascx.cs class inherits from your class you created in step 2.

Blank Asp.net MVC template

Is there a way I can get a blank MVC template for VS2008? Like the only that comes with MVC is nice to see what MVC is all about but it gets annoying when you want to make your own site and you first have to delete all the crap they generated for you.
Like I want to use my own authentication stuff since I understand what is going on and my own style sheets and stuff.
So I have to do through and delete everything ever single time so I wondering does anyone know of a template I can get that just has the basic structure of mvc and the bare minimum of stuff needed in the web.config file.
I don't know of any currently available, but at the least you can create the template you want by creating a custom Visual Studio Template.
Essentially, after deleting all of the files you don't want, do a File | Export Template in Visual Studio, follow the wizard to the promised land.
If you end up doing that, I am sure others would love to have it. I have just been too lazy to do it myself, and haven't really been creating a lot of new MVC projects, just working on the same one for months. :)
UPDATE: To respond to your comment: Although I haven't really looked too deeply into it, I don't know why you wouldn't be able to include in your project template access to the test project wizard. I cracked open the default ASP.NET MVC project template metadata file and found this near the bottom:
<WizardExtension>
<Assembly>Microsoft.VisualStudio.Web.Extensions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</Assembly>
<FullClassName>Microsoft.VisualStudio.Web.Mvc.TemplateWizard</FullClassName>
</WizardExtension>
If they can do it, I don't know why you wouldn't be able to as well. I am interested in looking into this more, but at the moment I am heading to bed - I am already up WAY too late considering I have a horrible chest cold. :)
This is the way you can create your own template. I'm quite sure there exists one already somewhere, but if it's not - just bake your own. Shouldn't be so hard.

ASP.NET Web Architecture Design

The problem I'm having with writing a web application architecture is that I want separate components that work together. By this I simply mean, for example, a navigation bar and the actual page content (as well as a header, which is static) in ASP.NET.
Now, here's where it gets interesting:
There are no two pages the same
The navigation pages on every page have security on them on a user-by-user basis
The navigation has links to other locations
The problem I'm mainly having is that you've usually got to have a full web page in Visual Studio, and if you have portions i.e. excluding your <html> tags then Visual Studio will end up underlining everything as incorrect.
The way is this application is currently being dealt with is using frames (yes, frames) to keep everything separate, but working together. I want to move away from this, although the web system is very large, and very important in that it must be available 24/7.
Any ideas?
Have you looked at Master Pages in ASP.NET 2.0? These can be used in conjunction with User Controls, and the Site Map Navigation.
Master Pages Quickstart Tutorial
MSDN Overview
Master Pages: Tips, Tricks, and Traps
Example Template Set
There's a really good book you should check out that might shed some light on your problem. It's "ASP.NET 2.0 Website Programming: Problem - Design - Solution", part of the Wrox series.
Is it not possible to implement UserControls for this? for example a navigation user control that can handle the security for itself etc etc.
Hope this helps a little.

Resources