MVC3控制器操作结果“记住”传入的标识 [英] MVC3 Controller Action Result 'Remember' Passed-in Id

查看:100
本文介绍了MVC3控制器操作结果“记住”传入的标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的控制器有两个作用的结果。概述和关于

I have two action results in my Controller. Overview and About.

public ActionResult Overview(int id)
{
    return View(new OverviewModel() { Project = db.People.Find(id) });
}

public ActionResult About(int id)
{
    return View(new AboutModel() { Project = db.People.Find(id) });
}

我要记住,在传递到概述id和使用它的关于为默认值。我不知道如何当用户切换从概述选项卡,以保持关于这个ID不变。

I would like to remember the id that was passed in to Overview and use it on the About as the default. I don't know how to keep this Id constant while the user switches tabs from Overview to About.

推荐答案

您可以尝试存储TempData的标识。也许这样的事情(未测试)

You can try storing the id in TempData. Maybe something like this (not tested)

public ActionResult Overview(int id)
{
    TempData["YourId"] = id;
    return View(new OverviewModel() { Project = db.People.Find(id) });
}

public ActionResult About(int? id)
{
    id = id ?? int.Parse(TempData["YourId"].ToString());
    return View(new AboutModel() { Project = db.People.Find(id) });
}

这篇关于MVC3控制器操作结果“记住”传入的标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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