保持视图名称和相应的控制器方法名称不同
keeping view name and corresponding controller method name different
我有一个名为 CreatePANApplication
的控制器方法,但我已经为此创建了名为 PANApplication
的视图页面。现在,当我尝试从另一个视图页面调用此方法时:
// dataTable code block
<td>
@Html.ActionLink("PAN Application", "CreatePANApplication", new { id = item.PANKey }, new { @class = "btn btn-warning" })
</td>
获取错误为:
The view 'CreatePANApplication' or its master was not found or no view engine supports the searched locations.
就是说我的controller名字不能和对应的view page名字不一样。但是很多时候我们要改view page名字,那怎么办呢?时间?
控制器class:
public ActionResult CreatePANApplication(int? id)
{
try
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var data = (from z in db.PANModels
where z.PANKey == id
select z).ToList();
if (data == null)
{
return HttpNotFound();
}
return View(data);
}
catch (Exception)
{
throw;
}
}
如果您的视图仍在名为控制器的文件夹中,或者您将视图放在共享文件夹中,则可以使用此
return View("PANApplication", data);
但如果您的视图位于不同的文件夹中,则必须使用完整路径
return View(" ~/Views/folder/PANApplication.cshtml", data);
我有一个名为 CreatePANApplication
的控制器方法,但我已经为此创建了名为 PANApplication
的视图页面。现在,当我尝试从另一个视图页面调用此方法时:
// dataTable code block
<td>
@Html.ActionLink("PAN Application", "CreatePANApplication", new { id = item.PANKey }, new { @class = "btn btn-warning" })
</td>
获取错误为:
The view 'CreatePANApplication' or its master was not found or no view engine supports the searched locations.
就是说我的controller名字不能和对应的view page名字不一样。但是很多时候我们要改view page名字,那怎么办呢?时间?
控制器class:
public ActionResult CreatePANApplication(int? id)
{
try
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var data = (from z in db.PANModels
where z.PANKey == id
select z).ToList();
if (data == null)
{
return HttpNotFound();
}
return View(data);
}
catch (Exception)
{
throw;
}
}
如果您的视图仍在名为控制器的文件夹中,或者您将视图放在共享文件夹中,则可以使用此
return View("PANApplication", data);
但如果您的视图位于不同的文件夹中,则必须使用完整路径
return View(" ~/Views/folder/PANApplication.cshtml", data);