The value “(string)” is invalid

倾然丶 夕夏残阳落幕 提交于 2019-12-05 10:32:02

I figured it out using a suggestion by Jasen in comments under the original post. It seems as though "Review" may have been used twice, although I could not find where. I changed the property name to "body" and now it works.

Thanks for all your help!

the problem is the name of the field is review:

@Html.EditorFor(model => model.Review)

as the name of the parameter in the control:

public ActionResult Create(MovieReview review)

Changing the name of the parameter should works too

Please try using

public class MovieReview
{
    public int Id { get; set; }

    [Range(1, 10)]
    [Required]
    public int Rating { get; set; }
    public string? Review { get; set; }
    public int MovieId { get; set; }
}

It does not work because your domain class has property named Review (public string Review { get; set; }) and method that is receiving updated domain class has parameter named review also (public ActionResult Create(MovieReview review)).

Change public ActionResult Create(MovieReview review) to public ActionResult Create(MovieReview movieReview).

I think in below model.Review and Model.Rating can't be directly accessible as your Mode is IEnumerable

     <th>
        @Html.DisplayNameFor(model => model.Rating)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.Review)
    </th>

your var name should not be same as a class name try this :

public class MovieReview
{
    public int Id { get; set; }

    [Range(1, 10)]
    [Required]
    public int ratingId { get; set; }
    public string reviewText { get; set; }
    public int movieId1 { get; set; }
}

Remove the @Html.ValidationSummary(true)

or

remove all ValidationMessageFor and change for(remove true) @Html.ValidationSummary()

Edit:

You want to be remove all ValidationMessageFor and change the ValidationSummary(true) to ValidationSummary()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!