View in Browser for MVC 3 ASP.NET - asp.net-mvc

In Visual Studio 2010, you can right-click an aspx page in a web forms app, or on the web forms app itself in the solution explorer, and you get "View in Browser" in your context menu.
In ASP.NET MVC projects, this item doesn't seem to be available in the context menu. The only way I know to run the app is to set the MVC app as a startup project and hit CTRL+F5. But, if there are two MVC apps in the solution, this doesn't really work. How do you accomplish this for mvc apps?
In my scenario, There are multiple users working on application on different controllers/view, How could they execute their view without changes the routes in Global.asax ?

This is a fundamental difference between MVC and Web Forms, and is crucial that you "get" this difference.
In Web Forms, everything revolves around the page. You can right click an aspx page and "view in browser" because there is a 1:1 correlation between the page and the URL. The page is at the top of the request, so to speak.
In MVC, everything revolves around the controller. The view is not part of the URL in any way, it's merely a template used by the controller to render the output. You can choose to have any action method render any view you want, it's not tied directly to the request.
Since the "view" is completely disconnected from the request, there is no option to "view in browser", because doing so makes absolutely no sense. You don't "view" views, they are templates that are rendered by the controller action method.

Related

VS 2015, MVC Core, Right Click -> View In Browser not going to the chosen View

In old days in ASP.Net class MVC, I can just Right click on the view and click on 'View in Browser' and I can go directly to the view...
for example, http://mysite/Home/RequestJob
However, in MVC Core, it's always opening http://mysite and it never goes to the View that I want to view directly.
Is there any setting I can change to get that feature back? Am I missing something?
I am using Visual Studio 2015 Professional Version.
In MVC, it depends on the routing configured, so opening the view directly will show you nothing as the view depends on the controller and you can reach the controller through the route which is mapped to the URL.

Embedding an MVC form inside the old master template architecture

I have an old Umbraco web application which was upgraded to v6 earlier this year.
It uses .NET ascx user controls and your standard .master pages as you'd expect.
I now need to create a brand new page which is essentially a booking form for an event.
I'd like to create it using MVC, as I do everything with MVC nowadays. I don't really want to duplicate the page layout / the frame. Is it possible to embed an MVC partial view inside the old master templates?
You can create the form in a .cshtml file and then add it as an Umbraco Macro. But the form couldn't use the MVC approach, it would have to be basic inline razor plus conditional statements. Which is fine but limiting. You could of course have the form posting to a controller action too but this get's a little tricky as it takes the form processing out of the page's event cycle.
Otherwise you are asking if you can reference an action in a masterpage, so no not really. I say "not really" because of course you can but it's unnatural and would make the project a nightmare for anyone to undestand of they were to pick it up. There is an article here as to how you might do it tho': http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx
Also, there is also the Umbraco MvcBridge package. This was something a lot of devs used prior to being able to build directly in MVC. Essentially you can set up Macros to point to actions etc. but still within the webforms mode.
It's a great half-way house but I'm not sure abut the compatibility with v6.

What happened to the popup dialog in asp.net mvc4

I am fairly new to mvc and I tried mvc4 when it was still in beta. I remember that when I started a new internet project, I got a popup dialog for log in and registration by default. I don't see that when I start a new project anymore, is that gone from the internet project?
I believe the popup dialog you're referring to was just the jQuery UI Dialog that the sample project used to use:
The project was built to support both a straight request to /Login and one via the jQuery UI dialog which was slimmed down to look like it was only a popup. It did this by making the Login action return a different View based on it being requested through the frame or not as detected by a value in the query string.
You can of course have this again, you'll just need to do it manually (or dig out one of the older templates) as it's no longer in the default templates.
To help you out, here's a couple of somewhat related questions that contain the sample code (ContextDependentView is one thing I remember from this template) and probably some hints on how to recreate it:
Generating a modal jQuery partial view with MVC4 does not work
ASP.NET MVC 4 and ContextDependentView
MVC4 - ContextDependentView - What does it mean?
It was removed from the Internet project templates in the final releases of MVC 4. The popup was pretty slick but I imagine there were issues/complexities they decided to eliminate by just keeping the view/page for logon and registration. In the older versions that had the pop-up they still had the view/page for logon because of how forms based authentication works. If the user is not authenticated/authorized for a web site/page MVC does a redirect to the logon page. This will not work with a JQuery popup dialog on the same page. The popup only worked if you clicked on the Logon link for the page. I am guessing that they decided since they need the view/page logon anyway to simplify things and keep it consistent by eliminating the popup dialog.
I have implemented an MVC Single Page Application (SPA) that only uses a JQuery dialog for a popping up a dialog for logon, and eliminates the need for logon page. But it required a fair amount of customization to authentication/authorization process on the server and used basic authentication on the client.

ReportViewer in MVC 4 partial

I am still unsure the best way to go about it.
I've read alsorts of resources, yet still no closer to a working solution.
I created a partial ASCX file. Added Report viewer to it, then rendered said partial in my CSHTML file. This was the closest I have come. In that I can see the report viewer, buttons etc. But for some reason the data never shows.
I have tried ASPX page inside an IFrame But this is not the way I want to go, about making this solution work.
Loading an ASPX page outright. But I lose my _Layout.cshtml main page style.
Some people suggest changing all sorts of things in config / Global.asax where as some say its not even necessary.
Ideally I want to have it as a partial in a page. But can deal with it being the only thing on the page, if I keep my main layout.
My experience with the older syntax / pages / non-MVC is limited to this project - trying to get this to work.
My data is linked through the components setup. The connection works fine in aspx page, as single page or iframe. But not in ascx.
The ReportView control requires ViewState to be enabled. In ASP.NET MVC such notion no longer exists. This means that you cannot use this control inside a native ASP.NET MVC view or partial. You can use it only in a classic WebForm (not in an ASP.NET MVC View) and the embed this WebForm inside an iframe within your current ASP.NET MVC view or partial. You have the possibility to render the report as an image for example and directly stream it to the response without using this control. Here's a blog post which illustrates the technique. So you could have a controller action which generates the report as a JPEG image and then link to this controller action from your view using the <img> tag. Unfortunately this makes only a static copy of the report and the user cannot interact with it.
You might also checkout this blog post which illustrates how you could run ASP.NET MVC and classic WebForms side by side.

MVC - Opening an asp.net page from the controller

I don't know if this is possible.
Can I have a mvc controller open a popup asp.net page? The asp.net page is within the mvc application, it's basically to run a crystal report viewer.
What happens just now is the mvc view loads and lists reports, then when a report is clicked it launches and exports to pdf. We now want this embedded in a web page instead of exporting to pdf(for various reasons one being no local download of the pdf report).
So sfter reading up i came across the solution to use a folder within the mvc app and use a webform in there. Now I'm trying to find how to open the .aspx pop-up from the controller where the report viewing is initiated.
Does that make any sense.
Any links/help is appreciated
Controllers in ASP.NET MVC are not supposed to open popups. You could do this using javascript inside the view. The window.open javascript function could be helpful:
window.open('/report.aspx', 'report');

Resources