我在不同项目(类库)中的视图模型。我添加了参考。但是当我从我的 mvc4 视图中调用它时,例如@model Fancy.Management.Model.Home.IndexModel。查看未识别它。我不知道是什么问题。
我的视图如下所示:
@model Fancy.Management.Model.Home.IndexModel
<html>
<head>
<title>Giriş</title>
</head>
<body>
@Html.BeginForm(){
<table>
<tr>
<td>Kullanıcı Adı:</td>
<td>@Html.TextBoxFor(m=>m.UserName)</td>
</tr>
<tr>
<td>Şifre:</td>
<td>@Html.PasswordFor(m=>m.Password)</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Giriş" /></td>
</tr>
</table>
}
</body>
</html>
我的控制器如下所示:
namespace Fancy.Web.Management.Controllers
{
#region Using Directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
#endregion
public class HomeController : Controller
{
#region Get
public ActionResult Index()
{
return View();
}
#endregion
}
}
我的模型如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fancy.Management.Model.Home
{
public class IndexModel
{
public string UserName { get; set; }
public string Password { get; set; }
}
}
您向模型添加了引用吗?好吧,这还不足以让您的视图看到它。
首先,打开位于以下位置的 web.config 文件Views
文件夹。然后,为模型类添加命名空间标记,如下所示:
<system.web.webPages.razor>
// ...
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
// ...
<add namespace="Fancy.Management.Model" />
// ...
</namespaces>
</pages>
最后改变你的@model
在你看来是这样的:
@model Home.IndexModel
问题应该消失了...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)