Tôi bị gộp với lệnh này và trợ giúp của bạn sẽ được ứng dụng nhiều nhất.Chuyển đổi tham số từ loại 'System.String' thành loại '' X 'không thành công vì không có trình chuyển đổi loại nào có thể chuyển đổi giữa các loại này
tôi nhận được lỗi:
The parameter conversion from type 'System.String' to type 'DataPortal.Models.EntityClasses.FeedbackComment' failed because no type converter can convert between these types
Các ModelState.IsValid
là không trên FeedbackComment.Comment
tài sản
Bất kỳ ý tưởng?
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; }
}
điều khiển phương pháp
//
// 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);
}
Và quan điểm
@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>
Thử thay đổi tên thông số nhận xét phản hồi trong hành động POST của bạn. Ngoài ra, bạn nên đặt CommentBy và CommentDate trong hành động POST của mình thay vì sử dụng trường bị ẩn – epzee
Cảm ơn bạn rất nhiều vì mẹo phụ của bạn. – MrBliz