全,
我有一个Html.Actionlink,它在我的控制器中调用一个方法,并且应该返回一个部分视图。我的部分视图显示在Index.cshtml中,部分视图是_ServerStatusList.cshmtl。
视图
@using (Html.BeginForm())
{
@Html.ActionLink("Start",
"StartServer",
null,
new { @class = "startButton" })
}控制器
[HttpGet]
public PartialViewResult StartServer(Model model)
{
model.StartServer("server01");
return PartialView("~/Views/Home/_ServerStatusList.cshtml", model.Servers);
}现在,单击“开始”按钮,所有功能在启动服务器时都能正常工作,但它返回不正确的视图。单击后,我被重定向到localHost/home/StartServer,它在一个空白页面上显示“运行”(启动服务器应该在我的服务器列表中这样说)。然后,如果我通过地址栏手动导航到服务器状态页,它将显示服务器正在运行(正如它应该说的那样)在我的_ServerStatusList.cshtml中。
我在项目的另一部分中使用Ajax ActionLink来单击按钮并返回部分视图。我也用这段代码为这个按钮做了尝试。
<input id="StartButton" type="image" value="submit" src="~/Images/start.png" alt="Start" height="25" />
@Ajax.ActionLink("Start", "StartServer",
new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "CurrentView"
}
)单击该按钮不起作用,但单击单词"start“可以执行类似于Html.ActionLink的操作。如果单击Start链接,它会将我带到Index.cshtml,显示在部分视图应该在的区域中运行,但不加载_ServersStatusList.cshtml。再一次,手动重定向,一切都是它应该是,运行和正确的格式。
如何让Ajax ActionLink将图像用作按钮,并在单击图像时返回正确的部分视图?
谢谢
发布于 2014-06-26 01:47:47
MVC足够聪明,可以找到您需要的视图,因此请将返回的PartialView更改为:
PartialView("~/Views/Home/_ServerStatusList.cshtml", model.Servers);
//To
PartialView("_ServerStatusList", model.Servers);这应该返回正确的视图:)。
https://stackoverflow.com/questions/24414177
复制相似问题