내 페이지는 아주 간단합니다. 사진을 보여주고 코멘트 섹션 (부분보기)이 있습니다. 새 댓글이 제출 될 때마다 부분보기 만 새로 고침하고 싶습니다. 그래서 나는 이것을 가지고 있습니다.
<tr>
<td>@Html.TextBox("NewComment")</td>
</tr>
<tr>
@Ajax.ActionLink("Submit", "InsertComment", new
{
Id = Model.userParticipation.Id,
CurrentPosition = 0,
CurrentComments = Model.currentComments,
NewCommentText = "???"
},
new AjaxOptions
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "CommentSection"
})
</tr>
내가 가진 유일한 문제는 NewComment TextBox에 입력 된 텍스트를 NewCommentText 변수 ( "???"문자열 대신)에 전달하는 방법을 모른다는 것입니다. 어떤 도움을 주시면 감사하겠습니다.
@Ajax.ActionLink
앵커 태그에 대한 마크 업을 생성합니다 (Ajax화된 동작이 연결됨). 그러나 서버에 새 주석을 제출하려면 사용자가 주석과 잠재적으로 양식을 입력 할 수있는 입력 필드가 필요합니다. 이 양식 제출에 대해 ajax화된 동작을 원하는 경우 Ajax.BeginForm
도우미 메서드를 사용할 수 있습니다 .
@using (Ajax.BeginForm("InsertComment", "Home", new
{
Id = Model.userParticipation.Id,
CurrentPosition = 0,
}, new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "CommentSection"
}))
{
<label>Enter comment</label>
<input type="text" name="NewCommentText" />
<input type="submit" />
}
<div id="CommentSection"></div>
그러면 이름 속성 값이 "NewCommentText"로 설정된 입력 요소가있는 양식 태그가 생성됩니다.
이것은 당신의 가정 작업을해야 InsertComment
다른 같은 paramters과 함께 입력 필드와 동일한 이름을 가진 매개 변수가 있습니다 (HomeController 내부) 액션 메소드를 Id
하고 CurrentPosition
.
[HttpPost]
public ActionResult InsertComment(string NewCommentText,int Id,int currentPosition)
{
// to do : Save and return some valid markup
return Content("To do : Replace this with useful html markup");
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다