AJAX发布中的问题 [英] Issue in AJAX Posting

查看:114
本文介绍了AJAX发布中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用ajax发布来保存我的其中一个视图(AddMember)的数据.调用转到相应的操作,并且保存了数据,我已将其指定给返回到首页(Index),这是另一个控制器,但它不会返回该视图将返回返回AddMember视图的操作结果.任何人都可以帮助我解决这个问题.即使我尝试浏览ajax还是没有成功.任何帮助将不胜感激.

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.

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

}


与其转到AdminHome中的索引,不如在同一控制器中建立索引.


Instead of going to the index in AdminHome it''s going to index in the same controller

推荐答案

似乎您未在重定向URL中指定控制器名称,而只是将您要重定向的操作名称设置为索引".请输入您要重定向到的操作的完整限定路径.

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.

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



使用上述方法可以帮助您实现目标.



Using the above method may help you to achieve your goal.


i)您可以尝试通过将操作路径作为参数传递来仅使用Redirect()方法.

ii)您也可以使用RedirectToRoute()方法进行检查,如下例:-
在RouteConfig.cs中用以下名称定义路由:
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 :
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 :-

return RedirectToRoute("Route1");



iii)如果没有任何效果,那么我怀疑路由映射肯定有问题.
请检查〜/App_Start/RouteConfig.cs"文件中的URL规则.


希望这次,以上三点之一肯定会有所帮助.



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.


这篇关于AJAX发布中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆