0
還有什麼我需要在我的代碼,請,我有這個至今:HttpPost與AJAX調用需要幫助
<script type="text/javascript">
function PostNewsComment(newsId) {
$.ajax({
url: "<%= Url.Action("AddCommentOnNews", "Home", new { area = "News" }) %>?newsId=" + newsId + "&newsComment=" + $("#textareaforreply").val(), success: function (data) {
$("#news-comment-content").html(data + $("#news-comment-content").html());
type: 'POST'
}
});
}
$("#textareaforreply").val("");
</script>
和
[HttpPost]
[NoCache]
public ActionResult AddCommentOnNews(int newsId, string newsComment)
{
if (!String.IsNullOrWhiteSpace(newsComment))
{
var currentUser = ZincService.GetUserForId(CurrentUser.UserId);
ZincService.NewsService.AddCommentOnNews(newsId, newsComment, currentUser.UserId);
Zinc.DataModels.News.NewsCommentsDataModel model = new DataModels.News.NewsCommentsDataModel();
var today = DateTime.UtcNow;
model.CommentDateAndTime = today;
model.NewsComment = newsComment;
model.Firstname = currentUser.Firstname;
model.Surname = currentUser.Surname;
model.UserId = CurrentUser.UserId;
return View("NewsComment", model);
}
return null;
}
<div class="actions-right">
<a href="javascript:PostNewsComment(<%: Model.News.NewsId %>);" class="button" id="post_button"><%: Html.Resource(Resources.Global.Button.Reply) %></a>
</div>
我不知道這是如何工作的,因爲它不在FF中工作? 另一件事是我不能傳遞返回null我必須通過JSON false ???
請幫忙嗎? 謝謝
感謝非常很多,但我認爲還是有一些遺漏,我得到了警報('糟糕的事情發生在服務器上')?我的控制器中的回報調用了一個叫做NewsComment的部分,我需要別的東西嗎?謝謝 –
當你調試你的服務器端控制器動作時發生了什麼?操作參數是否正確傳遞? –
着火錯誤: newsComment \t aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa NewSID的來源 NewSID的= 120&newsComment = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 動作參數包含正確的價值觀 –