How to bind html form properties to mvc controller method parameter? Working on binding controller post method to pure HTML form on the view.
Need to figure out how to fill the parameter and execute method using form data.
Controller method:
[HttpPost("addcomment")]
public JsonResult AddComment([FromBody]Comment comment)
{
if (comment.Name != null && comment.StarRating > 0)
{
_feedbackManager.AddComment(comment);
return Json("ok");
}
return Json("not ok");
}

Model:
public class Comment
    {
public Guid Id { get; set; } = Guid.NewGuid();
[Required]
public string Name { get; set; }
public DateTime Date { get; set; } = DateTime.Now;
public string CommentDetails { get; set; }
[Required]
public int StarRating { get; set; }
public bool Approved { get; set; } = false;
public string AdminAnswer { get; set; } = null;
    }

Html form:
<form id="form1" method="post">
<label for="name">Your name</label>
<input type="text" id="name" placeholder="Enter your name here please" />
<label for="starrating">How would you like to rate us?</label>
<input type="range" min="1" max="5" placeholder="choose the rate here" id="starrating" />
<input type="submit" id="btn1" onclick="addComment()" /> <!--onclick="addComment()"-->
</form>

JS script in the view:
function addComment() {
$.ajax({
url: "https://localhost:44342/addcomment",
datatype: JSON,
data: {
name: form1.name.value,
starrating: form1.starrating.value
},
success: function (result) {
console.log(result);
}
});
}

On form submission the method doesn't trigger and I get a 415 error.
Any help in this arena would be much appreciated.
Thank you in advance.

The problem is the Url in the ajax call. It should be "https://localhost:44342/"ControllerName"/addcomment". The best way to do it is use @Url.Action("Controller", "Action") to generate the url inside the cshtml view.
Another possibility is the data is not formatted correctly. Below is how I always submit form data to MVC via ajax.
<form id="form1" method="post">
<label for="name">Your name</label>
<input type="text" id="name" name="name" placeholder="Enter your name here please" />
<label for="starrating">How would you like to rate us?</label>
<input type="range" name="starrating" min="1" max="5" placeholder="choose the rate here" id="starrating" />
<input type="submit" id="btn1" onclick="addComment()" /> <!--onclick="addComment()"-->
</form>

<script>
function addComment() {
$.ajax({
url: "https://localhost:44342/addcomment",
type: "post",
data: $("#form1").serialize(),
success: function (result) {
console.log(result);
}
});
}
</script>

Add the name attribute to the form elements. Then jQuery serialize() will output a serialized string in a format that MVC can read. Also I usually don't specify datatype because jQuery automatically determines that.