'Error CS0411 ASP.NET Core Web Application
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
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>
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Priya Aptekar |
