RedirectToAction Usage In Asp.net Mvc

Dec 6, 2010

i want to make some questions about asp.net MVC,actually,i am not familiar with web developing.

But,i am assigned for web part.we are using like this.first,we create get set
properties for person data

public class Person
{
public int personID {get;set;}
public string personName {get;set;}
public string nric {get;set;}
}

and then after login,we put data in that class and we use RedirectToAction method like this,

return RedirectToAction("profile","person",new { personID = Person.personID});

it's working normally,but,parameter are shown at URL,how i hide them and also can i hide action name?

View 2 Replies


Similar Messages:

MVC :: Using ModelState With RedirectToAction?

May 18, 2010

I have created a custom validation attribute for a class. The validation is actually against one property of the class, but since it needs to be compared to another property of the class at runtime, I had to pull in everything from the input form, perform the validation and output the errors. This being the case, I manually added a ModelError to ModelState if the ModelStats.IsValid returned false. I have another thread that goes into this, as I still haven't been able to make the client-side validation work for the custom validation (built-in validation runs client-side without a problem).

Here's the issue: I want to use the Post/Redirect/Get pattern to avoid issues where users refresh their page and cause another post of the form data. If I complete my Controller action and return a View after assigning an error with ModelState.AddModelError, I get the user feedback with the red input field and error message shown. However, just returning a View like this makes you vulnerable to the repeated posts issue. I want to use RedirectToAction to perform a get and avoid this problem, but when I do that I no longer have the ModelState error feedback on my rendered View. Here're the calls I'm making:

[Code]....

I'd like to be able to redirect to a get action and retain the ModelState.

View 2 Replies

MVC :: Passing Int Value From RedirectToAction Method?

Nov 15, 2010

I want to pass a int value using RedirectToAction() method .

Here i have a Action method Index() which takes 1 parameter id in most of the cases this id cannot be null.

When i submit the form using Action method Edit(), i want to come again on Index page,so i am using method RedirectToAction("Index")

but here with Action Name i want to pass the id also. How can i do it?

View 3 Replies

Is There A Strongly Typed RedirectToAction In MVC 2

Oct 2, 2010

I wish to do something like this:

return RedirectToAction<SomeController>(c => Index(someparameter));

How to do this ?

View 2 Replies

Use Custom Route With RedirectToAction (asp.net Mvc)

Mar 8, 2011

I use the RedirectToAction with parameters in my action method

return RedirectToAction("ListThreads", "View", new { category = "1", subcategory = "49"});
After redirect the url comes out like this
http://domain/Forum/View/ListThreads?category=1&subcategory=49
I want it to be generated like
http://domain/Forum/View/ListThreads/1/49

How to do it?

Note : I already have a route in global.asax that is used by all the pages/links.

context.MapRoute(
"Forum_subcategory",
"Forum/{controller}/{action}/{category}/{subcategory}",
new { controller = "View", action = "ListThreads", category = "", subcategory = "" }
);

View 1 Replies

MVC :: RedirectToAction And Instance Of Class?7

Jan 27, 2010

I've a class that hold all the necessary properties. I want to pass the instance of that class in RedirectToAction. Right now, I can pass the instance but the action to which it redirect, doesn't receive that same instance. The target action has new instance of class.

eg.
AbcFilter a = new AbcFilter();
a.ABCname="abc";
RedirectToAction("AbcAction",a);
Public ActionResult AbcAction(AbcFilter a)
{// this method receives the "a" as new instance, but not the same that I pass in RedirectToAction
}

View 3 Replies

MVC :: RedirectToAction Crashing When A Controller Is Specified?

May 18, 2010

I've been using MVC since the previews of 1.0 and I think I know what I'm doing, but for the life of me I can not figure out why sometimes when I use RedirectToAction it crashes saying there is no route available. Consider this in MVC 2.0:

I'm registering on my site and I first hit the SiteController, which does its magic then I am to be redirected to my new dashboard, controlled by the... DashboardController. I never make it there. I specify the action and the controller in the redirect call, but it still crashes and burns. The only thing I can possible think of is because the DashboardController is its own area, but that still doesn't help me because by my understanding it should still work regardless.

View 1 Replies

MVC :: Unit Tests For Action Which Uses RedirectToAction?

Oct 13, 2010

I have Action method in a controller which uses RedirectToAction(actionName, routeValues[])I want to write the unit test for action method to check the following - 1. action name2. ViewData after executing the RedirectToAction.

View 1 Replies

MVC2 And MVC Futures Causing RedirectToAction?

Apr 12, 2010

I've been trying to get the strongly typed version of RedirectToAction from the MVC Futures project to work, but I've been getting no where. Below are the steps I've followed, and the errors I've encountered.

I created a new MVC2 app and changed the About action on the HomeController to redirect to the Index page.

Return RedirectToAction("Index")

However, I wanted to use the strongly typed extensions, so I downloaded the MVC Futures from CodePlex and added a reference to Microsoft.Web.Mvc to my project.

I addded the following "import" statement to the top of HomeContoller.vb

Imports Microsoft.Web.Mvc

I commented out the above RedirectToAction and added the following line:

Return RedirectToAction(Of HomeController)(Function(c) c.Index())

So far, so good. However, I noticed if I uncomment out the first (non Generic) RedirectToAction, it was now causing the following compile error:

Error 1 Overload resolution failed because no accessible 'RedirectToAction' can be called with these arguments:
Extension method 'Public Function RedirectToAction(Of TController)(action As System.Linq.Expressions.Expression(Of System.Action(Of TController))) As System.Web.Mvc.RedirectToRouteResult' defined in 'Microsoft.Web.Mvc.ControllerExtensions': Data type(s) of the type parameter(s) cannot be >inferred from these arguments. Specifying the data type(s) explicitly might correct this error.
Extension method 'Public Function RedirectToAction(action As System.Linq.Expressions.Expression(Of System.Action(Of HomeController))) As System.Web.Mvc.RedirectToRouteResult' defined in 'Microsoft.Web.Mvc.ControllerExtensions': Value of type 'String' cannot be converted to 'System.Linq.Expressions.Expression(Of System.Action(Of mvc2test1.HomeController))'.

Even though intelli-sense was showing 8 overloads (the original 6 non-generic overloads, plus the 2 new generic overloads from the Futures assembly), it seems when trying to complie the code, the compiler would only 'find' the 2 non-gneneric extension methods from the Futures assessmbly.

I thought this might be an issue that I was using conflicting versions of the MVC2 assembly, and the futures assembly, so I added MvcDiaganotics.aspx from the Futures download to my project and everytyhing looked correct:

ASP.NET MVC Assembly Information (System.Web.Mvc.dll)

Assembly version: ASP.NET MVC 2 RTM (2.0.50217.0)
Full name: System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Code base: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Mvc/2.0.0.0__31bf3856ad364e35/System.Web.Mvc.dll
Deployment: GAC-deployed

ASP.NET MVC Futures Assembly Information (Microsoft.Web.Mvc.dll)

Assembly version: ASP.NET MVC 2 RTM Futures (2.0.50217.0)
Full name: Microsoft.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null
Code base: file:///xxxx/bin/Microsoft.Web.Mvc.DLL
Deployment: bin-deployed

This is driving me crazy! Becuase I thought this might be some VB issue, I created a new MVC2 project using C# and tried the same as above.

I added the following "using" statement to the top of HomeController.cs

using Microsoft.Web.Mvc;

This time, in the About action method, I could only manage to call the non-generic RedirectToAction by typing the full commmand as follows:

return Microsoft.Web.Mvc.ControllerExtensions.RedirectToAction<HomeController>(this, c => c.Index());

Even though I had a "using" statement at the top of the class, if I tried to call the non-generic RedirectToAction as follows:

return RedirectToAction<HomeController>(c => c.Index());

I would get the following compile error:

Error 1 The non-generic method 'System.Web.Mvc.Controller.RedirectToAction(string)' cannot be used with type arguments

What gives? It's not like I'm trying to do anything out of the ordinary.It's a simple vanilla MVC2 project with only a reference to the Futures assembly.

I'm hoping that I've missed out something obvious, but I've been scratching my head for too long, so I figured I'd seek some assisstance.

If anyone's managed to get this simple scenario working (in VB and/or C#)

View 1 Replies

MVC :: Nested RedirectToAction After JQuery Post?

Jun 6, 2010

i built an MVC application, in one of my views, i'm activating an ActionResult using JQuery.$post in this ActionResult i'm using RdirectToAction to another ActionResult, this ActionResult is really reached and executed, but when i'm trying to use another RdirectToAction from here, its not happened.

View 6 Replies

MVC :: Controller Not Called From Actionlink Or RedirectToAction

Mar 4, 2011

I am new to MVC2 and have hit a wall. When I use an action link to jump back to a previous page that I have already been on, my controller is not called but the page is rendered correctly. Is this some sort of caching that I am not aware of? This also happens with a RedirectToAction call from another Controller. rfm is the Model...

return RedirectToAction("Search", rfm);

Here is the actionlink...

<%: Html.ActionLink("Search", "Search", "Reference")%>

View 3 Replies

MVC :: Return RedirectToAction() Passing Object?

Apr 9, 2010

I have the following ActionResult() method:

[Code]....

The method is called once the <form> is submitted. If the validation is good, it moves on to create a new user Once the new user is created, I want to redirect the user to a "ThankYou" page passing along the newly created user (object). The TempData["User"] trick seems to work like a charm! Then inside my ThankYou ActionResult() I do the following:

[Code]....

The problem I have is once the user has been redirected to the "ThankYou" page. If he decides to refresh (F5) his browser, the value in the TempData is lost.

What are my possibilities to overcome this issue?

Instead of passing an entire object to my "ThankYou" page, I initially thought of passing the ID of the newly created user and re-query my database to get the object.

The only problem is that the ID will be seen in the QueryString allowing the user to simply change the ID value and try to find other users...

Is my only other alternative to simply place the user object inside a Session? Is that my only other option?

View 6 Replies

Passing A Controller As A Parameter - Can't Get To RedirectToAction Method

Jun 15, 2010

My method looks like:

public static RedirectToResult(Controller controller, ...)
{
}

when I do:

controller.

I don't see RedirectToAction, how come?

I get RedirectToAction from within the controller's action, but not when I pass the controller as a parameter to another classes method.

View 3 Replies

MVC :: RedirectToAction() Go To View That Was Being Viewed Instead Of Home Page?

Oct 7, 2010

I am using some Html.ActionLinks to change the value of a Session variable. Right now I am RedirectToAction("Index","Home"). This puts the user back at the home page every time they change that value. I would like to return the user to the view they were one when they clicked that link instead of redirecting them back to the home page. How can I do that?

View 5 Replies

MVC :: RedirectToAction Failing To Match Default Route In MVC3

Jan 27, 2011

I have a Search Controller with an action method as follows:

public ActionResult Location(LocationSearchInputModel input)
{
// Get Results and pass cacheId in TempData
return RedirectToAction("results");
}
public ActionResult Results()
{
// Get cacheId from TempData and build Model
return View(model);
}

The call to RedirectToAction fails with the following error message:

Message: No route in the route table matches the supplied values.

My default Route is set up as follows:

routes.MapRoute(null, "{controller}.mvc/{action}/{id}/", new { controller = "Home", action = "Index", id = UrlParameter.Optional });

As the id Parameter in the default Route is optional shouldn't RedirectToAction("results") execute the SearchController's Results action?

It worked in MVC2 :/

View 5 Replies

MVC :: Ajax Call Causing RedirectToAction/ValidationSummary To Fail?

Jul 26, 2010

I think ive narrowed down my problem, I have a form but the "submit" buttons are being handled by Javascript - since i need to build arrays manually outside of the model for processing

[Code]....

I'm calling the Controller Action "Update" and passing it to string Arrays, when its finished - i want it to redirect to another action - it doesnt.

[Code]....

I just really wanna construct those arrays, and pass them to a controller...i think the ajax is waiting on a result and ignoring the redirect.

View 1 Replies

Pass A JQuery NotifyBar Requirement To The Next View In A RedirectToAction?

Jul 14, 2010

I'm using the jQuery NotifyBar quite nicely in an Index view to display business rule errors when a user e.g. clicks a delete link for an item than cannot be deleted. However, if the user adds a new item, they are redirected to the Create view. If the new item is successfully created, the Create action redirects back to the Index view.

My quandary is that I need (have been told) to show a success notification in the above scenario. Previously, to request a notification while remaining on the same view, I was using return JavaScript() for an action result, but when I use return RedirectAction() for the action result, I'm left with nowhere to put the return JavaScript().

The way I see this is that I need to: a) include information in the return RedirectAction() that tells the 'destination' view to show the notification, or b) invoke the notification in the 'source' view, instead of the return RedirectAction(), and tell it that when it closes/is closed, to perform the redirect to the 'destination' view.

View 1 Replies

MVC :: RedirectToAction Params And Breakpoints / Value Of 'projectID_DDL' Is Null When The Redirect Occurs?

Jul 12, 2010

I have an ActionResult method that loads a user-selected project. When the user makes a selection from a select html element, the id is passed in and loads the project. This works fine. The user can also submit the form, which saves certain information and then calls a RedirectToAction that passes the project id back into the load method. This is where the problem occurs. Here's the relevant code:

[Code]....

The problem is that the value of 'projectID_DDL' is null when the redirect occurs. I'm aware that during a form post that variable is automatically mapped to the name of the html element, so my first question is if that precludes referring to the parameter name as anything else, even in code. In regular methods, it doesn't matter what you call the variable, provided it's the correct type for the parameter it corresponds to, but ActionResult methods might differ. My second question is about break points. In order to test that the value of 'projectID_DDL' is what I passed in, I set a break point. It was never hit. I even tried adding a line before the return View statement, thinking perhaps that the return View statement threw the exception, and so its breakpoint wasn't being hit. This didn't work, either.

View 23 Replies

What Is The Usage Of Flush

Aug 17, 2010

I always have problem with the conception of flush who knows exactly what it means eg:

[Code]....

View 1 Replies

ADO.NET :: Usage Of Datatable In Vb.net?

Oct 19, 2010

how we write this code of C# in vb.net .i want to right this code in vb.net

[Code]....

View 5 Replies

Usage Of Cpu And Outofmemory Exception - How To Fix It

Nov 27, 2010

We have a web application based on asp.net 1.1. We deployed it on a web server but there is a problem about it. In the webserver sometimes cpu usage is increasing to 100% and outofmemory exception is occuring.

I think there are some wrong code inside the project but i don't know where it's.

Now, i want hear your advices about how to find problem and what kind of codes make cpu usage increased.

View 2 Replies

How To Diagnose IIS Pushing The CPU To 100% Usage

Nov 15, 2010

I have a web server with more than a few ASP.NET sites running on it. Every so often, i notice that IIS is pushing the server's CPU to 100%. The sites share application pools, per .NET version they are running.

What i'm looking for is a way to be able to pinpoint which site it is that is doing this, using some tool. If that tool happened to get down into the code to show it, that would also be nice. If not, i'm happy just knowing which site is causing the issue.

I've already tried using ANTS. However, with ANTS you need to know which site it is, and then have it running and waiting on said CPU-crashing web app. Not perfectly ideal.

View 4 Replies

Captcha Code Usage In Asp.net

Jan 30, 2010

how to insert the "captcha code" and its validation process in vb asp.net.... i vave searched every were but i could nat get its code..atleast tel me is it possible to do so or not

View 1 Replies

C# - Csharp - Jquery - Looking For A Better And Usage?

Feb 14, 2010

i have a little problem about using jquery...(i reeally do not know jquery but i forced to use it)

i am using vs 2008 - asp.net web app with c# also i am using telerik controls in my pages also i am using sqldatasources (Connecting to storedprocedures) in my pages my pages base on master and content pages and in content pages i have mutiviews in one of the views(inside one of those multiviews)i had made two radcombo boxes for country and city requirement like cascading dropdowns as parent and child combo boxes. i used old way for doing that , i mean i used update panel and in the SelectedIndexChange Event of Parent RadComboBox(Country) i Wrote this code :

[Code].....

View 1 Replies

C# - How To Write Memory Usage Log

Nov 10, 2010

We got "out of memory" issue on production servers. What API can we use to get live memory (physical and managed) usage of the ASP.NET application?

PS: we're forbidden to profile memory with tools.

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved