I am migrating a .Net
Application to .Net Core
. In .Net
Application, we were using bind
and include
keyword on the top of a model class for the LoginInfo as below:
[Bind(Include = "UserName,Password")]
But after conversion, it is showing this error:
The type or namespace name 'Bind' and 'Include' could not be found.
Can you suggest what can be added in place of those keywords in .Net core MVC.
CodePudding user response:
The Bind attribute exists in the Microsoft.AspNetCore.Mvc
namespace meaning that you need to import it like this:
using Microsoft.AspNetCore.Mvc;
If that isn't working, likely because this class exists in a class library outside of your ASP.NET Core web project, then you need to add a framework reference to Microsoft.AspNetCore.App
. To do this, edit your csproj file and add this:
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
See here for more details.
Finally, you don't need to name the Include
parameter, so it should simply look like this:
[Bind("UserName,Password")]
public class LoginInfo
{
//snip...