MVC 2 Map Routing From One Controller To Another?
Sep 25, 2010
I am using MVC 2.
I have 2 controllers called Application and Note. The application is a loan application. A note can be added to an application.
On my Index I have a grid that displays all the applications, and an action column with a link that says "Add Note".
In my Application controller I have action methods for create and edit. In my Note controller I have action methods for create, edit and delete.
I was wondering if the following is possible when the user clicks on the "Add Note" link to go to a URL like:
Application/1/Note/Create
1 is the application ID. Note would be the Note controller, and Create is the action method in the Note controller. Is something like this possible?
I started with the mapping in my global.asax, but not sure if it is correct:
routes.MapRoute(
null,
"Application/{ApplicationID}/{controller}/{action}",
new { controller = "Note", action = "Create" });
How would I create the link in my grid using the action link?
EDIT:
The grid above is on my Index view in my Home direcotry. So on this grid I need to concatenate the link to display as above. I'm struggling to create this link on my Index view. It's not concatenating correctly. Currently I have this:
Html.ActionLink("Add Note", "Create", "Note", new { ApplicationID = c.ApplicationID }, null)
And it is displaying as /Note/Create/?ApplicationID=1
I need it to display as:
/Application/1/Note/Create
View 1 Replies
Similar Messages:
Oct 21, 2010
I have this url working in my code:
[Code]....
I want to change my url to NOT to include the home/index [Code]....
ie, it should work like
[Code]....
My current Global.asax entry is like:
[Code]....
[Code]....
[Code]....
[Code]....
View 1 Replies
Apr 9, 2010
I have a controller method that is called with many different combinations of URL's. To overcome issue i am using optional parameters.here is my controller method signature...public ActionResult localMembersSearch(string Gender, string calling, [Optional]string Region, [Optional]string County, [Optional]string Town, [Optional]string queryvalues)the first two parameters are not optional but always expect
View 1 Replies
Dec 28, 2010
UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, that follows the UP(Unified Process). It uses a Grasp Controller pattern to interact with domain classes by some methods like NewSale(), AddNewItemToSale() and CloseSale. In windows form, I can instantiate a object of this class in the UI and then use its methods to perform the actions. This works well in Client apps, but when I use asp.net mvc, I cannot find a way to instantiate an object (one for each user) that was always visible for a Controller (MVC). I cannot insert as an attribute inside Controller because it always create a new one.
View 1 Replies
Jul 20, 2010
I tried everything I could find, but still does not work on IIS routing.
View 2 Replies
Dec 12, 2010
I am using:
ASP.NET 3.5 SP1 with Web Forms Routing thru Global.asax (System.Web.Routing and RegisterRoutes)IIS 7
Everything is working fine in my local machine, but it gives the following error in my hosting environment:
Could not load file or assembly 'System.Web.Routing, Version=3.5.0.0, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I did everything inside my web.config file mentioned in the following link:
[URL]
But I am still getting the above error.
What else am I supposed to do fix the error?
View 1 Replies
Feb 22, 2011
I have a Web application where i have added a reference to a RESTful WCF. I got the WCF url Routing to work in my webapplication by adding Inherits="RestService.Global" to the Web applications Global.asax.
<%@ Application Codebehind="Global.asax.cs" Inherits="RestService.Global" Language="C#" %>
But then i tried to create url Routing for the Web application and it does not work with the Inherits="RestService.Global" in the Global.asax. If i take it away it works fine. Is there a correct way to do this.
View 1 Replies
Jan 31, 2011
I'm trying to create my own CMS and I've gotten a little bit stuck at the stage of URL routing.
I want clean URLs without extensions and I'd like to be able to create and modify them in a web based interface without any messing around with IIS or actual files.
I've seen how to create a static route, but for that I need to go into my Global.asax file and manually add it.I would like to have all of these routes stored in a database so that I can easily modify them later.
Does anyone know how this can be achieved?
Just for extra information, I will be attempting to create a feature so that if a path exists, but is later changed, a 301 redirect is created to the new URL, is this also possible? (My first problem is the main issue, but thought I might ask this as well just in case it makes a difference)
View 2 Replies
Sep 2, 2010
How to handle asp.net mvc routing along with asp.net webform routing. I have merged my mvc app into my existing web application. In my web application i have implement routing as below:
routes.Add("View Product Details", new Route("Product/{City}/{Manufacturer}/{Name}/{ProductID}/{*ProductType}"));
Similarly i have implemented routing in mvc as below
routes.MapRoute("Product Details",
"Product/{City}/{Manufacturer}/{Name}/{ProductID}/{ProductType}",
new
{
controller = "Home",
action = "ProductDetails",
City= UrlParameter.Optional,
Manufacturer= UrlParameter.Optional,
Name= UrlParameter.Optional,
ProductID= UrlParameter.Optional,
ProductType= UrlParameter.Optional
});
How to handle both pages, as one is custom web form while other is asp.net mvc view?
View 1 Replies
Nov 6, 2010
my MVC2 delete and only my delete controller is refusing to return any class information. Its really similar to my edit function and the views are all auto-generated so I don't see the problem.
Function Delete(ByVal id As Integer) As ActionResult
View 4 Replies
Aug 16, 2010
I have a simple model where a Person has Gifts. I have a view which is a list of Gifts belonging to one Person.
My problem is with the Create action for a new Gift. I want it to default to the PersonID that we are already viewing the list of Gifts for. I tried simply passing the last PersonID (they are all the same)
Html.ActionLink("Create New", "Create", new { id = Model.Last().PersonID }) which works fine if there is already at least one Gift for that person but if this is the first Gift I don't have a value.
My Gift List controller knows the PersonID I want to pass but the view doesn't.
How do I pass this PersonID from my Gift List controller to my Gift Create controller via the Gift List view? Or is there a better way to do this?
View 2 Replies
May 30, 2010
I have a filter on my MVC web site. I display some records in a few different controller actions but when moving from one action to another I want to apply those filter values.
How can I persist values from controller to controller?
Should I use Session? TempData?
I am using Structure Map for IOC.
Maybe I could have a class that contains a Property for each Session Value that I use in my application and inject it on the controllers that need session?
View 10 Replies
Mar 14, 2011
How do you get the current action / controller name in a controller or class?
i can't show it in my view but that's not what i want.
View 1 Replies
Nov 30, 2010
Response.RedirectPermanent(Url); can redirect permanently to a url.
However, during my SEO process, I decided to change my routhing rule.
For example,
I change "/tag/{tag}-quotes" routing rule to "quoes-about/{tag}", but I don't want to lose all the traffic to old routing url.
What is the best way to handle this permanent redirection?
View 4 Replies
Jul 22, 2010
C#: HomeController.vb: works fine HttpPost RsvpForm gets the object filled with user input.
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using RsvpInC.Models; namespace RsvpInC.Controllers{ public class HomeController : Controller { //
[code]...
View 5 Replies
Jan 24, 2011
I have a User entity and a department entity. I have a UserViewModel and DepartmentListModel which has List of departments.
UserViewModel has a property of type DepartmentListModel .
Now on user/create action I need to populate DepartmentListModel by calling DepartmentController's list action. List action returns populated DepartmentListViewModel.
From UserController how do I set DepartmentListModel ?
I tried doing so
[Code]....
But RedirectToAction returns RediretToRouteResult
View 7 Replies
Mar 11, 2010
Say I have several Areas that are baed on user roles.Differnet roles have different functionality, but also have some "shared" functionality like say "Payments"Now, I created a PaymentController (and it's views for listing, creating messages) in Shared (not an area) and it works fine.
Would it be possible (and how?) to create a PaymentsController class in one of the Areas, have that inherit the PaymentController Class in Shared?
If I can do this, I can successfully share common functionality across areas, and at the same time extend the derived controller to include some 'area specific' functionality to common shared controllers. (Such as the "REturn to xxxx" text and route of the returnurl, which are a bit more complicated than I just made it sound)
View 3 Replies
Jan 19, 2011
How can i transfer control to a controller's method from a controller's method..I am having two Controllers Home and User.. After username and password are verified inHome Controllers method , i want to show the User Controllers index page , so i have to callindex method of Home controller..How can i do it.
View 5 Replies
Jul 12, 2010
I consider the following an error, and not a feature:
When posting a request, any parameters are held in the HttpContext.Request.Form as key/value pairs. This is perfectly fine for the recipient of the request. Unfortunately, however, further down the chain these values still exist and take precedent in binding over new parameters created during processing.
This is obvious in the RenderAction scenario. If a new parameter is created in a view and passed through RenderAction, if the parameter has the same name as one of the initial request parameters (or a form field for that matter), then MVC Binding will bind the initial request form value to the Action being called, and not the new parameter being defined in the RenderAction call. What's even more frustrating, is there is no easy way to override the initial form values.
It really does not make sense that a value defined in one context, should live throughout the entire processing context... at least without the developer being able to determine it should remain. At a minimum, any new parameter defined in the process with the same name should either a) be received as a parameter and not a form value; or b) override the form value.
View 5 Replies
Nov 3, 2010
I'm currently using URL Rewriting, but I recently stumbled upon this link on Rerouting, and it looks like it's quite simple yet powerful, and easier to implement than URL Rewriting, a "downside" probably is that configurations are not sitting on a web.config file but rather on the code itself, but I was wondering about the differences, and advantages of using one over the other. Having read some resources about routing, I can see the differences, and now I reformulate my question:
Is it worth it to move from URL Rewriting to Routing?
Are there any IIS-specific configurations that should be made?
Is it recommended to use it on a ASP.NET WebForms Application, or is it oriented to other kind of projects?
View 1 Replies
Feb 22, 2010
I've been doing research for a few days now and I know that I want to do ASP Routing over Rewriting. I found this great article:http://www.4guysfromrolla.com/articles/051309-1.aspx and also
http://blogs.msdn.com/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx. I write in VB.NET, these two articles are written in C#. I converted the code, but I must be missing something because my routing doesn't work correctly.
I was able to download the code from 4guys and it works fine. I found some differences between my results and theirs when I stepped through error checking. I added the 3 lines to the web.config file:
<system.web>
<httpModules>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0,[code]....
I right clicked on my project and added a reference to the System.Web.Routing dll.I created a Global.asax file in the root directory.
<%@ Application Language="VB" %>
<%@ Import Namespace="System.Web.Routing" %>
<script runat="server"> [code]....
Theirs shows the correct value of whatever you click on The requestContext variable, > HttpContext > System.Web.HttpContextWrapper > Request > System.Web.HttpRequestWrapper > PhysicalPath = "C:UsersNvXDesktopMyWebsiteWebResource.axd"
Theirs shows PhysicalPath = "C:\Users\NvX\Desktop\RoutingDemo\Products\Pavlova" (Pavlova was the link I clicked on)
When I query the database using LINQ, it never finds WebResource.axd and redirects to the NotFound.aspx page. When I load Default.aspx, I want it to load that page. If I type /tjnevis (which is a username in the database), I want it to go to a page where I can put together a profile, pulling the information for that username, which I can figure out. It's the routing that I'm having trouble with. If I could get it to work correctly, I think the PhysicalPath should look similar to the 4guys example I downloaded.
View 4 Replies
Aug 6, 2010
I have an ASP.NET MVC app and I have a WebForm page I built in the MVC due to a tutorial on how to do something I needed to do, but it was all in WebForm style. Ive tried to figure out how to do the same thing in MVC format but cant figure it out. So I was needing to figure out how to use this page in my MVC app. But when I try to go to the page, it gives me the error "Page cannot be derived from ViewMasterPage unless Page derives from ViewPage." So I had to make a new standard MasterPage also.
The situation is this. I have a search bar located in the MVC ViewMasterPage thats on every page that is derived from it. Once a user submits info in the search bar, it calls the WebForm Search.aspx page and displays the results on the Search.aspx page. I want the URL to be like "http:///search//. The Search.aspx page is located in the root of the project. How would I get the results Im looking for?
View 1 Replies
Nov 2, 2010
I have a url which will take the following form:
/AuditReview/Review/15d49a66-5c11-492c-921f-9e1700bd2618
I cannot get this to route, my routes look like this:
MvcRoute.MappUrl("{controller}.mvc.aspx/{action}/{auditEventUid}")
.WithDefaults(new {controller = "AuditReview", action = "Review"})
.WithConstraints(new { controller = "AuditReview", action ="Review", auditEventUid = new GuidConstraint() });
MvcRoute.MappUrl("admin/{controller}.mvc.aspx/{action}")
.WithDefaults(new { controller = "audit", action = "index" })
.WithConstraints(new{controller = "audit"})
.AddWithName("admin", routes);
MvcRoute.MappUrl("{controller}.mvc.aspx/{action}")
.WithDefaults(new {action = "Index"})
.AddWithName("Default", routes);
View 2 Replies
Feb 21, 2011
I used to build my web apps in asp.net in such there is only one page witch is default.aspx
http://localhost/mywebapp1/?q=blog/posts/get/42
I do parse 'q' by myself and do all processing. I don't really need to all MVC staff. I just want to remove "?q="
View 2 Replies
Aug 6, 2010
This is more of an ASP.NET Routing question than MVC, so I will gladly move this post to another forum if prompted!
I am using ASP.NET Routing without using MVC.
I am trying to implement the following URLs:
[URL]
[URL]
[URL]
Each page can have sub-pages:
[URL]
or even sub-sub-pages:
[URL]
I am currently implementing this as follows:
1) GLOBAL.ASAX
[Code]....
2) ROUTE HANDLER CLASSES
[Code]....
View 2 Replies