ram*_*ral 5 c#-4.0 asp.net-mvc-4
如何将现有视图附加到操作?我的意思是,我已经将这个视图附加到一个动作,但我想要的是附加到第二个动作.
示例:我有一个名为Index的Action和一个View,同名,附加到它,右键单击,添加视图......,但现在,如何附加到第二个?假设一个名为Index2的Action,如何实现呢?
这是代码:
//this Action has Index View attached
public ActionResult Index(int? EntryId)
{
Entry entry = Entry.GetNext(EntryId);
return View(entry);
}
//I want this view Attached to the Index view...
[HttpPost]
public ActionResult Rewind(Entry entry)//...so the model will not be null
{
//Code here
return View(entry);
}
Run Code Online (Sandbox Code Playgroud)
我用Google搜索,无法找到合适的答案......这可能吗?
您不能将操作"附加"到视图,但可以使用Controller.ViewMethod 定义操作方法要返回的视图
public ActionResult MyView() {
return View(); //this will return MyView.cshtml
}
public ActionResult TestJsonContent() {
return View("anotherView");
}
Run Code Online (Sandbox Code Playgroud)
http://msdn.microsoft.com/en-us/library/dd460331%28v=vs.98%29.aspx