2010-06-22 4 views

답변

1

대부분은 CSS and jQuery입니다. 따라서 ASP.NET MVC에 한정되지 않습니다.

모델 :

public class MyModel 
{ 
    public string Message { get; set; } 
} 

컨트롤러 :

public class HomeController : Controller 
{ 
    public ActionResult Index() 
    { 
     return View(new MyModel()); 
    } 

    [HttpPost] 
    public ActionResult Index(MyModel model) 
    { 
     return View(model); 
    } 
} 

보기 : 이것은 단지 마크 업, 스타일과 스크립트가 같은 페이지에 혼합 샘플입니다 물론

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<AppName.Models.MyModel>" %> 

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 

    <style type="text/css"> 
    #alert 
    { 
     overflow: hidden; 
     z-index: 999; 
     width: 100%; 
     text-align: center; 
     position: absolute; 
     top: 0; 
     left: 0; 
     background-color: #fff; 
     height: 0; 
     color: #000; 
     font: 20px/40px arial, sans-serif; 
     opacity: .9; 
    } 
    </style> 

    <% if (!string.IsNullOrEmpty(Model.Message)) { %> 
     <div id="alert"><%: Model.Message %></div> 
    <% } %> 

    <% using (Html.BeginForm()) { %> 
     <%: Html.EditorForModel() %> 
     <input type="submit" value="Alert me!" /> 
    <% } %> 

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
    <script type="text/javascript"> 
     $(function() { 
      var $alert = $('#alert'); 
      if ($alert.length) { 
       var alerttimer = window.setTimeout(function() { 
        $alert.trigger('click'); 
       }, 3000); 
       $alert.animate({ height: $alert.css('line-height') || '50px' }, 200).click(function() { 
        window.clearTimeout(alerttimer); 
        $alert.animate({ height: '0' }, 200); 
       }); 
      } 
     });  
    </script> 


</asp:Content> 

. 실제 응용 프로그램에서는 CSS와 스크립트를 외부화해야합니다.

+0

샘플 작업 코드를 제공하십시오. –

+0

@MuraliVijay CSK, 샘플이 제공됩니다. –

+0

나는 당신의 모범을 사랑합니다. 다시 게시하지 않고도 그렇게 할 수 있다고 생각합니까? 감사! – Mathieu

0

이것은 서버 측의 불가지론 자입니다. jQuery와 CSS로 간단하게 만들 수 있습니다. 필요한 HTML 자체를 간단한 MVC로 출력 할 수 있습니다. 이것은 흥미로운 구현 인 것 같습니다 : http://jnotify.codeplex.com/.

Grz, Kris.