Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的控制器中,我通过以下方式返回特定模型的视图
return View(model);
(那里没有魔法)。现在这个视图包含很多元素,比如不同的选项卡。我想向该视图发送和接收参数,以便可以根据发送的参数显示特定选项卡。
如何才能做到这一点?
一个问题有两个。我将一一回答:
传递信息以查看
一种选择是使用 ViewBag。其次是扩展您的模型以包含有关应传递哪个选项卡的信息
从客户端传递信息
在操作链接中,您必须生成参数以传递应该打开的视图。此参数将附加到查询字符串,因此您可以轻松地将其映射到控制器的输入参数或从查询字符串中读取它。
您可以使用ViewBag或ViewData。
ViewBag
ViewData
在您的控制器中
ViewBag.test = "some text";
在你看来
@ViewBag.test