Posts

Showing posts with the label asp.net-core-mvc

How do I implement Post([FromBody] IMessage msg) in my .Net Core 2.1 web api Controller?

Image
Clash Royale CLAN TAG #URR8PPP How do I implement Post([FromBody] IMessage msg) in my .Net Core 2.1 web api Controller? I get the following exception when I send a simple JSON structure implementing the interface IMessage: Could not create an instance of type TestService2.IMessage. Type is an interface or abstract class and cannot be instantiated. Path 'Id', line 2, position 7. Action parameters by default have to be concrete classes that can be initialized by the model binder. Only custom model binders can be used to achieve what it is you are trying to do. – Nkosi Jul 27 at 14:53 My question would be Why do you want to use am interface for the model parameter? – Nkosi Jul 27 at 15:00 ...

Why aren't ASP.NET MVC tag helpers creating the correct link?

Image
Clash Royale CLAN TAG #URR8PPP Why aren't ASP.NET MVC tag helpers creating the correct link? I have an asp.net core MVC project with scaffolded Identity, and the tag helpers in the _LoginPartial view are acting wonky. In the Razor view, the link looks like this and don't navigate to any page or view. <a class="nav-link" asp-area="Identity" asp-page="/Account/Manage/Index">Manage Account</a> but for some reason it's being rendered like this (taken from the dev console in chrome): href="/?area=Identity&page=%2FAccount%2FManage%2FIndex" I don't know why this is happening and I can't figure out how to get it to render properly and allow navigation to the correct page. You should be using asp-controller=".." and asp-action="..." – Stephen Muecke 2 days ago ...

Form validation of empty strings

Image
Clash Royale CLAN TAG #URR8PPP Form validation of empty strings How can I make the form first name input field not accept empty strings with space characters " " " " <form asp-action="SaveRegistration" autocomplete="off"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="form-group"> <label asp-for="FirstName" class="control-label"></label> <input asp-for="FirstName" class="form-control" /> <span asp-validation-for="FirstName" class="text-danger"></span> </div> Model: public class ContactInfo { [Required(ErrorMessage = "This field is required")] [StringLength(50)] [DisplayName("First name")] public string FirstName { get; set; } } With [Required] attribute t...