Mvc控制器返回保留旧视图名称 [英] Mvc controller return retaining old view name

查看:74
本文介绍了Mvc控制器返回保留旧视图名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,



这是一个奇怪的!



我正在返回一个视图

返回

OK,

Here's an odd one!

I am returning a view
return

View("Index", clients)



,生成的Razor页面实际上是索引页面。

但是,

URL保留了旧的Razor页面名称(EditRecord.cshtml),这会导致在通过我的网格进行paigng时调用该页面的操作。



CONTROLLER ...


and the resulting Razor page is, in fact the Index page.
HOWEVER,
The URL is retaining the "old" Razor page name ("EditRecord.cshtml") which is causing that page's action to be called when paigng through my grid.

CONTROLLER...

[HttpGet]
        public ActionResult UpdateClient()
        {
            // Perists record chagnes to database
            const string PROCNAME = "UpdateClient";

            try
            {
                int id = Convert.ToInt32(Request["ID"]);
                // Routine (actually stored proc.) will check for the existence of this ID
                //     and update an existing records or create a new.
                //Request.Form["name"].ToString();

                //clientMethods.SaveClient(Convert.ToInt32(collection["ClientGrid.id"].ToString()), collection["Name"], collection["ClientGrid.Email"]);
                clientMethods.UpdateClient(Convert.ToInt32(Request["id"].ToString()), Request["Name"].ToString(), Request["Email"].ToString());
                List<Client> clients = clientMethods.GetClients();
                return View("Index", clients);
            }
            catch (Exception ex)
            {
                ProgLog.Log(ex.Message, PROCNAME, MODNAME);
                return null;
            }
        }









< b>网址:

http:// localhost:52545 / Client / UpdateClient?ID = 1& Name = Stu + Pidasso& Email = stupiddaso%40gmail.com



上面的/ Client / UpdateClient是PREVIOUS SUBMIT。



什么给你的人?



我的尝试:



[HttpPost]

[HttpGet]



根本没有使用表单提交并依赖表单集合。



我应该添加我正在使用grid.mvc抓取分页的URL信息。并不总是赞赏。





URL:
http://localhost:52545/Client/UpdateClient?ID=1&Name=Stu+Pidasso&Email=stupiddaso%40gmail.com

In the above /Client/UpdateClient are the PREVIOUS SUBMIT.

What gives, you people?

What I have tried:

[HttpPost]
[HttpGet]

Not using form SUBMIT at all and relying on form collection.

I should add that I'm using grid.mvc that grab URL info for pagination. Not always appreciated.

推荐答案

好的。

想出来。

我是个笨蛋! />


我只需要调用返回RedirectToAction(原始视图);

而不是返回View(Index) ,客户);


来自我的控制器动作的
调用savedata()例程。
OK.
Figured it out.
I am a dumbass!

I just needed to call a return RedirectToAction(original view);
instead of return View("Index", Clients);

from my controller action that calls the savedata() routines.


这篇关于Mvc控制器返回保留旧视图名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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