2017-05-08 39 views
0

我無法在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"; 
} 
+0

你'UserModel'不'public' –

+0

更新@StephenMuecke – Abi

+1

查看錯誤列表中的警告。 – CodeCaster

回答

0

在Vs2013更改視圖,強類型的含義:

插入在視圖的開頭

@model "project/classname"; 

,然後使用用戶的唯一財產

例如:

@Html.TextBoxFor(m => model.LicenseNo) 

在Vs2017

確保您有

Microsoft.CSharp.dll

,並檢查是否存在以下

在全球.asax.cs添加ViewEngines.Engines.Add(新的RazorViewEngine());到的Application_Start()方法

+0

我已經有在beginging中定義的模型....'@model ItemMasterDetailsModel' – Abi

相關問題