从视图中删除邮件?

时间:2016-10-19 11:42:28

标签: javascript c# ajax

每次用户点击un读取div区域应该删除,下面是我的HTML和javascript。目前发生的事情是当你点击未读时它会在后端而不是在前端屏幕中执行所有操作,我认为它与我的JavaScript行$('#Unreadmessage').closest(".messagearea").remove();有关,请提示

<div class="alert alert-default alert-dismissible messagearea" role="alert" style="background: rgb(233, 233, 233);">

<button class="close" aria-label="Close" type="button" data-dismiss="alert"><span aria-hidden="true">×</span></button>

<div id="Unreadmessage" class="markmessage" data-messageid="@message.Id">

<p class="small"><i class="fa fa-envelope" aria-hidden="true"></i> Unread</p></div>

<p class="small"><i class="fa fa-calendar" aria-hidden="true"></i> @message.CreatedOn.ToString("dd MMM yyyy")</p>
                                            <p class="small" style="font-weight: bold;"><i class="fa fa-info" aria-hidden="true"></i> Claim ref. @message.CaseNumber</p>

<p>@message.Message <a href="@Url.Action("Details","Enquiry" , new { id = @message.EnquityId })">More.</a></p>

</div>

以下是我的Javascript

$("#Unreadmessage").click(function () {
var messageId = $(this).data("messageid"); //need to pass this message ID to controller.
var isread = true; //True by default
//I need to pass the messageID to server which is CRM
$.ajax({
url: "@Url.Action("MarkMessage", "Enquiry")", //Need to add my URl here
type: "POST",
data: { messageId: messageId, isread: true }, //Get messageId and isread values
dataType: "json",
success: function (response) {
 $('#Unreadmessage').closest(".messagearea").remove();  
  }
    });

1 个答案:

答案 0 :(得分:0)

如果您的意思是删除内容就像点击x一样,那么也可以通过在p(未读容器)上放置data-dismiss =“alert”来实现。

要仅删除未读取的内容,最好在单击“更多”时将后端更新为“已读”(例如)。然后,您必须决定是显示读取还是不显示任何内容。

<p data-dismiss="alert" class="small"><i class="fa fa-envelope" aria-hidden="true"></i> Unread</p>