私は自分自身にC#とasp.netmvc3を教えるための簡単なブログアプリケーションを開発しています。コメントを投稿に更新する必要がある段階で立ち往生しています。
私のコードのコメントクラスは次のとおりです。
public class Comment
{
public int CommentID { get; set; }
public string Name { get; set; }
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[DataType(DataType.MultilineText)]
public string CommentBody { get; set; }
public int BlogID { get; set; }
public virtual Blog Blog { get; set; }
}
ブログの詳細ページに、名前、メールアドレス、コメントを記載したコメントフォームがあります。コードは次のとおりです。
<div class="editor-label">
@Html.LabelFor(model => model.Comment.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Comment.Name)
@Html.ValidationMessageFor(model => model.Comment.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Comment.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Comment.Email)
@Html.ValidationMessageFor(model => model.Comment.Email)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Comment.CommentBody)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Comment.CommentBody)
@Html.ValidationMessageFor(model => model.Comment.CommentBody)
</div>
<p>
<input type="submit" value="Add Comment" />
</p>
コメントが正しいブログIDで更新されるように、これでブログIDを渡す方法がわかりません。
ありがとう。