내보기에 단추가있어서 div
의 피드백 양식을로드합니다.DIV에서 부분보기를 열고 제출 단추를 사용하십시오.
<script>
// open feedback window
function openFeedback() {
$('#feedback-container').show();
$('#feedback-container').load('@Url.Content("~/Feedback/")');
}
</script>
<div id="feedback-container"></div>
<button id="feedback-button" onclick="openFeedback()">
Give feedback
</button>
이것은 Feedback
컨트롤러에서 Index
보기를로드합니다. 안에는 다른 Submit
버튼이있는 양식이 있습니다.
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
... some controls ...
<input type="submit" value="Send" />
}
그리고 컨트롤러 :
public ActionResult Index()
{
return View(new Feedback());
}
[ValidateAntiForgeryToken]
[HttpPost]
public ActionResult Index(Feedback feedback)
{
SaveFeedback(feedback);
return PartialView("ContactConfirm");
}
내가 양식을 다시 게시 될 때 feedback-container
의 내부 메시지 "감사합니다", 대신에 전체 페이지가로드와보기를 반환 할 - 그리고 그것이 보기 만 ContactConfirm
.
부분 뷰를 div로 반환 할 수 있습니까?
이것은 좋은 대답이지만 jquery.unobtrusive-ajax.js를 참조하고 있는지 확인해야합니다. 그렇지 않으면 브라우저가 현재 페이지에서 벗어납니다. – heymega
@heymega 상기시켜 주셔서 감사합니다. 답변을 수정할 것입니다. – tweray