我的弹出局部视图:
@using StudiModel
@model StudiModel.StudiCommentsPopup
@{
Layout = "~/Views/Shared/_TopNavLayout.cshtml";
}
@Model.MessageUser
foreach (var item in Model.CommentsList)
{
@item.CommentText
}
@using (Html.BeginForm())
{
<div class="input-control textarea" data-role="input-control" style="width: 85%">
@Html.TextArea("Message", new { @placeholder = "Add a comment", id = "Comment", style = "width:720px" })
</div>
<input type="button" id="postComment" value="Add a Comment" />
@Html.HiddenFor(Model => Model.PMessageId)//Why can't I put this here, because I want to pass the text and this id to controller
}
我需要一个jquery将值发布到控制器中并在单击添加按钮时自行关闭,如何将两个值传递给jquery? 感谢
我的控制器:
[HttpPost]
//jquery shoul get me two values, id and text box value
public ActionResult PostComments(string parentMsgId,string Comment)
{
StudiMessageDetails comment = new StudiMessageDetails();
var balObject = new BusinessLogic();
//comment.UserId = (StudiUserInfoViewModel)Session["UserInfo"].
comment.MessageId = parentMsgId;
comment.CommentText = Comment;
comment.UserId = ((StudiUserInfoViewModel)Session["UserInfo"]).UserId;
var message = balObject.AddComment(comment).Message;
return View();
}
好吧,我在局部视图中需要一个jquery来将值传递给我的控制器..它是.Net .. 要打开我使用的弹出局部视图:
<span class="list-subtitle"><span class="place-right icon-flag-2 fg-red smaller" onclick="ShowMessage('@item.MessageId');">23
</span>
和jquery:
<script>
function ShowMessage(msgid) {
$.Dialog({
overlay: false,
shadow: true,
flat: false,
title: 'Studidesk - Conversations',
content: '',
onShow: function (_dialog) {
var html = [
'<iframe width="800" height="480" src="/Channel/Comments?msgid=' + msgid + '" frameborder="0" allowfullscreen></iframe>'
].join("");
$.Dialog.content(html);
}
});
}
答案 0 :(得分:0)
$('#postComment').on('click', function () {
var txtComment=$("#Comment").val();
var hidId=$("#PMessageId").val();
window.location.href = "Mycontroller/postComment?parentMsgId="+hidId+"&Comment="+txtComment+";
});