매우 간단한 부분 뷰가 있으며 저는 아약스폼을 사용하고 있습니다. 내 부분보기에서 한 sigle textArea 및 제출 단추가 있습니다. 문제는 텍스트 영역에 무엇을 쓰든가 컨트롤러에 데이터를 보내지 않고 오히려 텍스트를 "주석"으로 보냅니다. 아무 것도 쓰지 않으면 유효성 검사가 완벽하게 작동합니다. 보기가 컨트롤러에 올바른 데이터를 전송하지 않습니다.
뷰 모델
:public class NoteCommentViewModel
{
public Int32 Id { get; set; }
[Required(ErrorMessage="Hey, if you dont wanna write then why pressing the button !!")]
public string Comment { get; set; }
public DateTime CommentDate { get; set; }
public long UserId { get; set; }
public double Rating { get; set; }
public Guid NoteId { get; set; }
}
컨트롤러 :
//
//GET:/Notes/Comment/
public ActionResult Comment(string id)
{
ViewBag.NoteId = id;
var m = new NoteCommentViewModel()
{
NoteId = new Guid(id),
UserId = Convert.ToInt64(Session["LoginUserId"].ToString()),
//Comment=""
};
return PartialView(m);
}
//
//POST:/Notes/Comment
[HttpPost]
public ActionResult Comment(NoteCommentViewModel nvm)
{
NoteRatingComments comment = new NoteRatingComments();
comment.Comment = nvm.Comment; // Here I always have "Comment", regardless whatever I write in the page.
comment.EntryDate = DateTime.Now;
comment.NoteId = nvm.NoteId;
comment.UserId = nvm.UserId;
comment.Rating = 3.00;
dc.NoteRatingComments.AddObject(comment);
dc.SaveChanges();
return Content(Boolean.TrueString);
}
뷰 : 여기
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Ajax.BeginForm("Comment", "Notes", null, new AjaxOptions
{
UpdateTargetId = "Comment-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = "commentSuccess"
}, new { id = "commentForm" }))
{
<div style="margin-top:20px;">
<div id="commentSuccess"></div>
<div class="comentPic">
@{
long UserId = Convert.ToInt64(Session["LoginUserId"].ToString());
string Fullname = Session["LoginUserFullName"].ToString();
}
<img src='https://graph.facebook.com/@UserId/picture' height="100px" width="100px"/>
</div>
<div class="commentText">
@Html.HiddenFor(m => m.UserId)
@Html.HiddenFor(m=>m.NoteId)
@Html.TextAreaFor(m => m.Comment, new { style = "width:600px;height:120px;" })
<br />
@Html.ValidationMessageFor(m => m.Comment)
<div style="text-align:right;">
<input type="submit" value="Comment" name="comment" class="btn"/>
</div>
</div>
<div class="clear"></div>
</div>
}
이해에 대한 오류 ...의 스크린 샷이다. 나는보기에 "데이터"를 쓰고 있지만 컨트롤러에서 나는 "코멘트"를 얻고있다 .. 어디에서 오는가 ?? 누군가가 나에게 문제를 식별하는 데 도움이 될 수있는 경우
좋은 것입니다 ...!
heyy ... Thats super cool. 내 문제를 해결하고 나는 또한 좋은 것을 배웠다. 고마워. m8. – kandroid