MVC 控制器重定向到 Jquery 选项卡
我在 MVC 中有一个控制器,成功创建命令后需要将视图重定向到由 jquery 制作的联系人选项卡。这是我对控制器的内容:
[HttpPost]
public ActionResult Create(Contact newContact, int id)
{
try
{
if (ModelState.IsValid)
{
gogoDB.AddToContacts(newContact);
gogoDB.SaveChanges();
return RedirectToAction("Index" + "/" + id, "Client");
}
else
{
return View(newContact);
}
}
catch
{
return View(newContact);
}
我尝试重定向到的网址是
http://localhost:xxxxx/Client/Index/2#contacts
当前代码 ReturnToAction("Index" + "/" + id, Client") 重定向到
http://localhost:xxxxx/Client/Index/2
的不是我想要的。我也尝试过 Redirect(" Client/Index/" + id + "#contacts") 但我得到的 url 是这样的:
http://localhost:xxxxx/Contact/Create/Client/Index/2#contacts
如您所见,问题是我正在从联系人控制器内部调用客户端控制器生成的页面。Id 工作正常在所有的例子中,
请帮忙!
I have a controller in MVC that after successful create command needs to redirect the view to a contact tab made by jquery. Here is what I have for controller:
[HttpPost]
public ActionResult Create(Contact newContact, int id)
{
try
{
if (ModelState.IsValid)
{
gogoDB.AddToContacts(newContact);
gogoDB.SaveChanges();
return RedirectToAction("Index" + "/" + id, "Client");
}
else
{
return View(newContact);
}
}
catch
{
return View(newContact);
}
The url I am trying to redirect to is
http://localhost:xxxxx/Client/Index/2#contacts
Current code ReturnToAction("Index" + "/" + id, Client") redirects to
http://localhost:xxxxx/Client/Index/2
which is not what I want. I have also tried Redirect("Client/Index/" + id + "#contacts") but the url I get is something like this:
http://localhost:xxxxx/Contact/Create/Client/Index/2#contacts
As you can see, the problem is that I am calling a page generated with client controller from inside the contact controller. Id works right in all examples.
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以做类似的事情。
视图
控制器
I think that you can do something like that.
View
Controller