私はこの1つで困惑しており、'System.String'型から '' X '型へのパラメータ変換は、型変換器がこれらの型の間で変換できないため失敗しました
私はエラーを取得する:
The parameter conversion from type 'System.String' to type 'DataPortal.Models.EntityClasses.FeedbackComment' failed because no type converter can convert between these types
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>
:とPOSTメソッドただ、このような
に使用されたFaturamentoモデルからプロパティ...
私のために解決は何がGETパラメータ名を変更しました。 POSTアクションでFeedbackCommentパラメータ名を変更してみてください。また、隠しフィールドを使用するのではなく、POSTアクションでCommentByとCommentDateを設定する必要があります。 – epzee
2次チップをありがとうございます。 – MrBliz