working with an .aspx page with in asp.net mvc 2 - asp.net-mvc

I'm new to asp.net mvc.
I just created the default asp.net mvc project in VS and I can see that when I make a call to a controller's action like this: "http://localhost:2528/Home/About" my Home controller has an action method "About" that is returning the about.aspx view. however I am seeing not seeing the .aspx extension in the browser's url. And when I try to browse to "http://localhost:2528/Home/About.aspx" i get a 404 error.
I have a requirement where I need to create a .aspx page that is passed an arguement via the url like this: "http://... /myAspxPageHere.aspx?argName=myArg"
I'm not sure how to do this with asp.net MVC. Any help and/or code examples would be greatly appreciated.
Thanks

ASP.Net MVC does not use the .aspx extension in client-facing URLs.
If you want to accept arguments from the querystring, you should add parameters to your action methods.

Related

Why Controller suffix removed from URL in MVC/API application

In MVC/web API application controllers are suffix with Controller keyword.
But when any action called or rendered on browser, the URL generated in browser will remove the Controller suffix.
For example,
I have controller HomeController with action UserList.
When this action rendered in browser, the URL generated in browser will be looks like http://localhost:123/Home/UserList
So I want to know that from where Controller suffix is removed from browser's URL?
ASP.NET MVC uses Convention over Configuration. MVC identifies the right Controller and its Action method from the URL using the Route data. More details about MVC pipeline/lifecycle are here and here.
It would be good to take a look at the DefualtControllerFactory of ASP.NET Core in github.

How to pass data from MVC Controller to ASPX Page?

I have two projects (one ASP.NET MVC and one ASP.NET Webform). I am showing the aspx page of webform project in one panel of the cshtml page of MVC project.
I wanted to pass a value from the action method of controller to the aspx page and I need to use it in the webform project. Could some one help how to achieve this?
Thanks in advance!

ASP.NET MVC Displaying Static Help Website

I'm trying to add Help to my ASP.NET MVC project.
The "help" website contains static pages about the features in my ASP.NET application.
I have added the content for this website into my ASP.NET MVC project and have added a hyperlink that will open the Help in its own window.
However, when I try to access the content, the application attempts to route to the Help controller.
How do I display the help website within my MVC application?
I am not sure you can do this within the context of an MVC application. I would consider just building an empty controller with an Index action (HelpController -> public ActionResult Index()) and just return the view name (cshtml file), shouldn't be any reason you can't rename your static html file to cshtml even if you aren't using razor (although I am not 100% sure without trying that the extension change is necessary). Also I would argue that if this ever needs more functionality you have the scaffolding in place to make non-static mods. Disabling routing within the context of an MVC solution honestly doesn't make the most logical sense. The only other choice would be if you hosted it in a different IIS site (but I don't think I would recommend that unless you have a huge help library).
Use IgnoreRoute when you configre your routing, for example, create a folder "help" in your app's root. Then load it with all your html help files. Then to ignore that route:
routes.IgnoreRoute("help");
You should then be able to access it by http://myapp.com/help/whatever.html

single page application (SPA) home page error

I am new to asp .net MVC. I am trying to implement SPA model for my new application. I am using asp .net web api in asp .net mvc4 project. I have only api controllers in my project. I dont have any MVC controllers.
I have deleted auto generated views from the views folder. I have created a index.cshtml page outside the views folder. This page is my layout page that renders other pages in it. I have set this page as startup page. And also i have commented out the default MVC route from routeconfig.cs file.
The problem is when i run the application, the index.cshtml does not render. I get an error saying "This type of page is not served - Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect."
Please help
Make sure you keep the root Views folder, and create a folder called Home within that. Place your Index.cshtml file within the Home folder.
Do not comment out the default MVC route. In MVC, you can't hit a view directly, as you do in WebForms, which is why you get the error when you try to hit Index.cshtml.
Make sure you have a HomeController within the root Controllers folder, with an action called Index that looks like this:
public ActionResult Index()
{
return View();
}
Your view should now render when you browse http://localhost/Home/Index or even just http://localhost as by default, the controller and action will be set to Home/Index.

How do I navigate to a Web Forms ASPX page from my MVC3 application?

I find myself having to create a Web Form page in my MVC3 application to host the ReportView control, for displaying rdlc reports for my users. I see quite an abundance of advice on how to go about this all, and it seems pretty simple.
What I would like to know is how do I get from a Razor based view to this report viewer page? Do I simply 'hard-code' a content url to the page, or is there some more polite way?
You can do this by adding route in global.asax file.
routes.MapRoute(
"ReportRoute", // Route name
"Reports/{reportname}", // URL
"~/Reports/{reportname}.aspx" // File
);
Check out LeftyX solution with source code.
You could use the Url.Content helper:
Show me the report

Resources