【发布时间】:2026-01-20 06:55:01
【问题描述】:
我有观点Index.cshtml:
@{
ViewBag.Title = "Index";
}
<h2>Add</h2>
<p>Begin building a question set by clicking the button below.</p>
<input type="button" value="Create" onclick="location.href='@Url.Action("Product", "Add")'" />
在我的 AddController 中调用 Product 操作:
public ActionResult Product()
{
ViewBag.Partial = true;
return PartialView("Product");
}
我想要实现的是:
当用户加载页面时,我的部分视图 (Product.cshtml) 中的内容是隐藏的,但是当他们单击“创建”按钮时,该按钮会在我的 AddController 中调用 Product 操作,然后我想加载Product.cshtml 对我的Index.cshtml 的部分视图,因此后者仍然具有其原始内容,但这次将Product.cshtml 注入其中。
目前,它只返回部分视图,而不是两个视图。
这在 MVC 中可以实现吗?
【问题讨论】:
-
您有想要展示的产品列表吗?一种方法是使用 Product 的 EditorTemplate,因此 Product.cshtml
-
您发布的代码没有这样做。它将用户发送到另一个视图。
标签: c# asp.net-mvc