Преобразование параметра из типа 'System.String' в тип ''X' не удалось, потому что ни один конвертер типов не может преобразовать между этими типами

Я в тупике с этим, и ваша помощь была бы очень признательна.

Я получаю ошибку:

Преобразование параметра из типа 'System.String' в тип 'DataPortal.Models.EntityClasses.FeedbackComment' не удалось, потому что нет Конвертер типов может преобразовывать между этими типами

Свойство ModelState.IsValid не работает в свойстве FeedbackComment.Comment

Есть идеи?

public class FeedbackComment : IFeedbackComment
{
    [Key]
    public int Id { get; set;}

    public int FeedbackId { get; set; }

     [Required(ErrorMessage = "Please enter a Comment")]
    public string Comment { get; set; }

    public DateTime CommentDate { get; set; }

    public string CommentBy { get; set; }
}

Методы контроллера

//
    // GET: /FeedbackComment/Create

    public virtual ActionResult Create(int feedbackId)
    {
        var comment = new FeedbackComment {FeedbackId = feedbackId, CommentBy = User.Identity.Name, CommentDate = DateTime.Now};
        return View(comment);
    } 

    //
    // POST: /FeedbackComment/Create

    [HttpPost]
    public virtual ActionResult Create(FeedbackComment comment)
    {

        if (ModelState.IsValid)
        {

            _feedbackCommentRepository.Add(comment);

            return RedirectToAction(MVC.Feedback.Details(comment.FeedbackId));
        }

        return View(comment);
    }

И вид

@model DataPortal.Models.EntityClasses.FeedbackComment
@{
ViewBag.Title = "Create Comment";
}
<h2>Create Comment</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>Feedback Comment</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.Comment)
    </div>
    <div class="editor-field">
        @Html.TextAreaFor(model => model.Comment, new{@class = "TextEditor"})
        @Html.ValidationMessageFor(model => model.Comment)
    </div>


    @Html.HiddenFor(model=> model.CommentDate)
    @Html.HiddenFor(model=> model.CommentBy)       
    @Html.HiddenFor(model=> model.FeedbackId)

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
}

<div>
@Html.ActionLink("Back to Comment Details", MVC.Feedback.Details(Model.FeedbackId))
</div>
29
задан Stacked 16 November 2016 в 14:00
поделиться