我無法在VS 2013中的TextboxFor()
方法中編寫表達式。下面是asp.net mvc中Textbox的剃鬚刀代碼。無法根據用法推斷方法的類型參數。查看包和html幫助程序錯誤
@Html.TextBoxFor(m => m.User.LicenseNo)
其是否顯示錯誤在VS 2013:
用於方法「System.Web.Mvc.Html.InputExtensions.TextBoxFor(System.Web.Mvc.HtmlHelper,系統中的類型的參數。 Linq.Expressions.Expression>,System.Collections.Generic.IDictionary)'不能從用法推斷。嘗試明確指定類型參數
但是,當我在VS 2017中打開相同的解決方案時,它的工作正常。
同樣是用下面的代碼
ViewBag.Title = "Role Configuration";
錯誤VS 2013的情況下:
編譯一個動態表達所需的一個或多個類型不能被發現。你錯過了一個參考嗎?
編輯
下面是我在視圖中使用模型UserDetailsModel
。
public class UserDetailsModel
{
public UserDetailsModel();
public List<RoleModel> Roles { get; set; }
public List<CodeItemModel> Status { get; set; }
public UserModel User { get; set; }
}
public class UserModel
{
public UserModel();
public string Email { get; set; }
public string FirstName { get; set; }
public int Id { get; set; }
public string LastName { get; set; }
public int LicenseNo { get; set; }
}
而且我已經把下面的代碼在視圖(.cshtml文件)的頂部...
@{
ViewBag.Title = "Role Configuration";
}
你'UserModel'不'public' –
更新@StephenMuecke – Abi
查看錯誤列表中的警告。 – CodeCaster