简体   繁体   English

在MVC 4中查找警报或通知

[英]Looking for alerts or notifications in MVC 4

Watch the next image. 观看下一张图片。

在此处输入图片说明

It's something like an alert or notification and some of them have a close button to the right of the border. 这有点像警报或通知,其中一些在边框的右侧有一个关闭按钮。

I would like to implement that in my MVC 4 project where the alert can closed (I guess this is done using COOKIES) 我想在我的MVC 4项目中实现该功能,在该项目中可以关闭警报(我想这是使用COOKIES完成的)

I don't know if this can be done using JQUERY o some HtmlHelper extension. 我不知道是否可以使用JQUERY某些HtmlHelper扩展来完成。 Can you mention me name components which I can use? 您能提及我可以使用的名称组件吗? I really don't know any one of them. 我真的不认识他们中的任何一个。

approach 1: you can make a partial view, and hide it when they click on the x in a corner 方法1:您可以制作局部视图,并在他们单击角落的x时将其隐藏

you would show the partial view selectively based on a value int he viewmodel 您将基于viewmodel的值选择性地显示局部视图

in the container viewmodel you could have...
@{if (Model.IsVisitor)
       @Html.Partial("CustomAlert",Model.Message);
 }};

and then you could have a parital view CustomAlert.cshtml 然后可以有一个局部视图CustomAlert.cshtml

<div id="custom-alert" class="custom-alert">
   <div id="close-custom-alert" class="custom-alert-top-right">&#x2716;</div>
   <p style="width:95%"> @Model </p>
</div>

<script>
       $('#close-custom-alert').click(function(){$('#custom-alert').hide()});
</script>

<style>
   .custom-alert { position: relative; background-color:cornsilk; }
   .custom-alert-top-right   { position : absolute; top:5px; right:5px; padding-5px; }
</style>

approach 2 see jquery ui modal dialog http://jqueryui.com/dialog/#default and http://jqueryui.com/dialog/#modal . 方法2参见jquery ui模态对话框http://jqueryui.com/dialog/#defaulthttp://jqueryui.com/dialog/#modal You can pop the dialog based on a value in the view like 您可以根据以下视图中的值弹出对话框

$(function(){
 if ('@Model.IsVisitor'){
  $( "#dialog-modal" ).dialog({
   height: 140,
   modal: true
  });
 }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM