我的模型public class UserRegistrationViewModel{ public string Description { get; set; }}指數@model UserRegistrationViewModel<form asp-controller="Demo" asp-action="RegisterTextArea" method="post"> <textarea asp-for="Description"></textarea> <button type="submit">Test</button></form>那里很完美,但是如果我在類庫項目中聲明了我的實體域,會發生什么情況?如何將那個類的地址放在我的剃刀頁面上?這句話對嗎?我目前犯了一個錯誤@model DomainEntities.ViewModel.UserRegistrationViewModel 另一個例子我目前正在犯錯誤@model Domain.ViewModel.UserLogInViewModel@{ ViewBag.Title = "Login";}<h2>Login</h2><form method="post" asp-controller="Account" asp-action="Login" asp-route-returnurl="@Model.ReturnUrl"> <div asp-validation-summary="ModelOnly"></div> <div> <label asp-for="Username"></label> <input asp-for="Username" /> <span asp-validation-for="Username"></span> </div> <div> <label asp-for="Password"></label> <input asp-for="Password" /> <span asp-validation-for="Password"></span> </div> <div> <label asp-for="RememberMe"></label> <input asp-for="RememberMe" /> <span asp-validation-for="RememberMe"></span> </div> <div> <input type="submit" value="Login" /> </div></form>
1 回答

SMILET
TA貢獻1796條經驗 獲得超4個贊
所以如果你的Web
項目直接引用你的DomainEntities
項目那么是的,它會起作用你只需要指定完整namespace
的ViewModel
@model My.Full.Namespace.DomainEntities.ViewModel.UserRegistrationViewModel
或者更清潔:
@using My.Full.Namespace.DomainEntities.ViewModel @model UserRegistrationViewModel
對于第二個錯誤,你的namespace
to the ViewModel
is different, ie Domain
vsDomainEntities
很可能是你namespaces
寫錯了或者拼寫不完整。
如果您使用某種方式Dependency Injection
來注入您DomainEntities
,那么如果沒有一些瘋狂的解決方法,您的方式將行不通。Web
需要直接依賴于您的項目ViewModels
。
最后,我質疑你把你ViewModels
放在一個單獨的項目中,我會說除了最極端的情況外,你ViewModels
應該在你的Web
項目中。
- 1 回答
- 0 關注
- 123 瀏覽
添加回答
舉報
0/150
提交
取消