Click here to Skip to main content
15,894,546 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I'm trying to save data using ajax posting for one of my views(AddMember).The calls goes to the corresponding action and data gets saved i have given it to return home page(Index) which is another controller but it wont return that view instead it will go to action result for returning the AddMember view.Can anyone help me with this issue.Even i have tried to navigate through ajax but that was not successfully.Any help would be greatly appreciated.

C#
public ActionResult Register(MemberDetail user)
{
using (Election_TVM context = new Election_TVM())
{
context.MemberDetails.Add(user);
context.SaveChanges();
return RedirectToAction("Index", "AdminHome");
}

}

Instead of going to the index in AdminHome it's going to index in the same controller
Posted
Updated 8-Jun-14 22:40pm
v2
Comments
SRS(The Coder) 6-Jun-14 9:16am    
Please elaborate properly(descriptively or put some code examples) your question to make understand who will give you the answer...

It seems you have not specified the Controller name in redirection URL and just putting the action name as 'Index' you are trying to redirect. Please put the whole qualified path for the action to which you want to redirect.

C#
RedirectToAction("action name", "controller name"); 


Using the above method may help you to achieve your goal.
 
Share this answer
 
Comments
Mani89 9-Jun-14 3:32am    
Hi Smruti,
Thanks for the immediate reply.I have tried that but that is also not working
Instead of going to the index in AdminHome it's going to index in the same controller. Please refer to the updated question..
Nelek 9-Jun-14 4:23am    
You should add your code using the widget "improve question", you can use the code tags and choose language of programming, it will be easier to read for the rest and... the easier to read, the easier to give you help
SRS(The Coder) 9-Jun-14 6:49am    
Please see this :-
http://www.dotnet-tricks.com/Tutorial/mvc/4XDc110313-return-View()-vs-return-RedirectToAction()-vs-return-Redirect()-vs-return-RedirectToRoute().html
Mani89 9-Jun-14 4:38am    
okay sorry...will improve the question...
i) You may try with only Redirect() method by passing the path for the action as parameter.

ii) Also you can check with RedirectToRoute() method as below example :-
Define the route in RouteConfig.cs with a name :
C#
public static void RegisterRoutes(RouteCollection routes)
{
 routes.MapRoute(
 "Route1", // Route name
 "Product/", // URL 
 new { controller = "Product", action = "List"} // Parameter defaults
 );
}


Now at the place where you need to redirect :-
C#
return RedirectToRoute("Route1");


iii) If nothing works then i suspect definitely something wrong in route mapping.
Please check the URL rules in the "~/App_Start/RouteConfig.cs" file.


Hope this time one of the above three point will definitely of help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900