0

I am not able to write expression in TextboxFor() method in VS 2013. Below is the razor code for Textbox in asp.net mvc.

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

which is showing an error in VS 2013 :

The type arguments for method 'System.Web.Mvc.Html.InputExtensions.TextBoxFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, System.Collections.Generic.IDictionary)' cannot be inferred from the usage. Try specifying the type arguments explicitly

But when I open the same solution in VS 2017 its working fine.

The same is the case with the following code

ViewBag.Title = "Role Configuration";

Error in VS 2013:

One or more types required to compile a dynamic expression cannot be found. Are you missing a reference?

EDIT

Below is my Model UserDetailsModel used in the view.

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; }
}

And I have placed the below code at the top of the view (.cshtml file)...

@{
    ViewBag.Title = "Role Configuration";
}
Abi
  • 283
  • 3
  • 16

2 Answers2

0

In Vs2013 change your view to strongly typed meaning:

insert in the beginning of the view

 @model "project/classname"; 

and then use only the property of the user

for example:

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

In Vs2017

make sure you have the

Microsoft.CSharp.dll

and also check if the below exists

In Global.asax.cs add ViewEngines.Engines.Add(new RazorViewEngine()); to the Application_Start() method

kostas.kapasakis
  • 920
  • 1
  • 11
  • 26
  • I already have the model defined in the beginging....`@model ItemMasterDetailsModel` – Abi May 08 '17 at 10:09
0

After searching over and over I came across the link below.. works like a charm..

clear component model cache and Enjoy coding

Community
  • 1
  • 1
Abi
  • 283
  • 3
  • 16