0

I'm currently working on a project for one of my classes and I suddenly received this error when I tried to run it:

Severity Code Description Project File Line Suppression State Error
CS0411 The type arguments for method 'IModelExpressionProvider.CreateModelExpression<TModel, TValue>(ViewDataDictionary, Expression<Func<TModel, TValue>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. Proj1BankApp C:\Users\jross.000\source\repos\Proj1BankApp\Views\Home\Index.cshtml 1 Active

Visual Studio Screenshot

It directs me to my Index.cshtml file but nothing else and I don't know how to fix it, so any help would be appreciated. Index.cshtml:

@model BankAppModel
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body style="height: 50px">
    <form id="form1" runat="server">
        <h1>@ViewBag.Title</h1>
        <div class="row">
            <label asp-for="Name" class="control-label col-sm-3">Name: </label>
            <input asp-for="Name" class="form-control col-sm-3" />
            <span asp-validation-for="@Model.Name" class="text-danger col"></span>
        </div>
        <div class="row">
            <label asp-for="TransactionMonth" class="control-label col-sm-3">Month: </label>
            <input asp-for="TransactionMonth" class="form-control col-sm-3" />
            <span asp-validation-for="@Model.TransactionMonth" class="text-danger col"></span>
        </div>
        <div class="row">
            <label asp-for="TransactionDay"class="control-label col-sm-3">Day: </label>
            <input asp-for="TransactionDay" class="form-control col-sm-3" />
            <span asp-validation-for="@Model.TransactionDay" class="text-danger col"></span>
        </div>
        <div class="row">
            <label asp-for="TransactionYear" class="control-label col-sm-3">Year: </label>
            <input asp-for="TransactionYear" class="form-control col-sm-3" />
            <span asp-validation-for="@Model.TransactionYear" class="text-danger col"></span>
        </div>
        <div class="row">
            <label class="control-label col-sm-3">Balance: </label>
            <input class="form-control col-sm-3" name="balance" readonly />
        </div>
        <div class="row">
            <input class="col offset-sm-3 pl-0" type="submit" name="deposit" value="Deposit" asp-for="Deposit" formmethod="post" />
            <input class="col offset-sm-3 pl-0" type="submit" name="withdraw" value="Withdraw" asp-for="Withdraw" formmethod="post" />
            <input class="btn btn-secondary" asp-action="Index" type="submit" name="clear" value="Clear" formmethod="post" />
        </div>
    </form>
</body>
</html>
1
  • Hi , please add the CSHTML contents as part of the question and not screenshot Commented Feb 18, 2021 at 0:49

2 Answers 2

2

In my case there was a hidden input property was declared, which was not declared in model class, so i removed that hidden input and error was gone, this happens when you copy paste the code from another form. than you.

Sign up to request clarification or add additional context in comments.

Comments

0

This is likely on a line like InputFor(m=> m.Something)

Actual method you're calling has generic arguments, like Method<T>(T arg1, ..) and the compiler attempts to infer them by looking at the types (the class) of the arguments you pass in..

for example: if you call a method with signature Method<T>(T value) as Method("hi") the compiler is smart enough to figure out this is actually Method<string>("hi")

But this doesn't always work, for example if the type of the argument cannt be resovled at compile time.

You likely have to find this call in your cshtml file and either add the type <typehere> manually or you may have a different compile error in your code which prevents the compiler from resolving this type.

Try scrolling down to the bottom of the error list and see if there are any other errors you can resolve. If not, look for the above.

7 Comments

Hmm, there seems to only be two of the same errors and they both point to line 1 in Index.cshtml file. I also can't seem to find anything related to what you described.
it might be due to @ViewBag.Title.Remove it and see if it fixes. If so, might need to cast it. @ViewBag.Title as string
asp-for and asp.validation-for also calls functions. Check those as well
I just tried that and it didn't change anything, unfortunately. It used to not do this at one point, so I don't know what happened.
Oh, sure! I'll try the asp related suggestion and see what happens.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.