在MVC中,如何在编辑页面上单击保存后返回到详细信息页面? [英] In MVC, how can I get it to return to the details page after clicking save on the edit page?

查看:167
本文介绍了在MVC中,如何在编辑页面上单击保存后返回到详细信息页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自动生成的MVC集;在这种特殊情况下,我只使用详细信息和编辑视图页面,因为id在别处确定,并且创建,删除和索引都不适用。因此,我有一个不同的控制器直接调用带有id的Details页面,并且从Details页面可以正常进入Edit页面。这没有改变。



我的问题是当用户点击编辑页面上的保存时,它遵循其通常的路由模式到控制器名称,默认返回到索引页面。当然,我希望它返回到详细信息页面(成功保存更改后),并完全忽略索引页面。



编辑页面上的Html.Beginform()中没有参数,没有其他我可以看到的预先确定它会跳回到Index页面之后点击保存。



如何在编辑页面上点击保存后返回详细信息页面?



提前感谢您提供的任何帮助。



我有什么尝试过:



我尝试从索引控制器操作重定向,但它只是转到空白页。



public void Index()

{

RedirectResult rr = RedirectPermanent(@myController \Details \+ ViewBag.Client_ID);

}



我还尝试在Edit页面的其他无参数的Html.Beginform()指令中添加controller,action和id参数;但是,尽管它根据需要重定向到详细信息页面,但编辑页面中的编辑无法保存。

I have autogenerated MVC set; and in this particular case, I'm utilizing only the Details and Edit view pages, as the id is determined elsewhere and create, delete, and index are all not applicable. Consequently, I have a different controller directly invoking the Details page with the id and from the Details page you can go to the Edit page as normal. That's unchanged.

My problem is when the user clicks Save on the Edit page, it follows its usual pattern of routing to the Controller name, which defaults to returning back to the Index page. I, of course, want it to return to the Details page (after successfully saving the changes), and ignore the Index page completely.

There are no parameters in the Html.Beginform() on the Edit page and nothing else that I can see that predetermines that it will jump back to the Index page after clicking Save.

How can I get it to return to the Details page after clicking Save on the Edit page?

Thank you in advance for any help you can afford me.

What I have tried:

I tried a redirect from the Index controller action but it just goes to a blank page.

public void Index()
{
RedirectResult rr = RedirectPermanent(@"myController\Details\" + ViewBag.Client_ID);
}

I have also tried adding the controller, action, and id parameters in the otherwise parameterless Html.Beginform() directive in the Edit page; but although it does redirect to the Details page as desired, the edits from the Edit page fail to save.

推荐答案

您好,



如果您要发布表单并保存,则在成功保存后,使用RedirectToAction方法将用户返回到Details页面。

Controller.RedirectToAction Method (System.Web.Mvc) [< a href =https://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction(v=vs.118).aspx\"target =_ blanktitle =New Window > ^ ]

这将重定向用户并将用户登陆到所需的页面。



谢谢
Hello,

If you are posting the form and saving, then after successfully saving, return the user to the Details page using the RedirectToAction method.
Controller.RedirectToAction Method (System.Web.Mvc)[^]
This will redirect the user and land the user to the desired page.

Thanks


这篇关于在MVC中,如何在编辑页面上单击保存后返回到详细信息页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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