zoukankan      html  css  js  c++  java
  • MVC4中重复使用JQuery Mobile Dialog的做法实践.

    第一步:建立mobile项目类型

    第二步:添加针对对话框的的DialogController.cs:

    建立这个Controller的目的是此Dlg可以反复使用,把它做成一个固定界面,其他的Controller也可以调用。

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 using System.Web.Mvc;
     6 
     7 namespace MvcDlgTest.Controllers
     8 {
     9     public class DialogController : Controller
    10     {
    11         //
    12         // GET: /Dialog/
    13 
    14         public ActionResult Index(string OKAction,string CancelAction,string CtrlName,string Message)
    15         {
    16             if (string.IsNullOrWhiteSpace(CtrlName))
    17                 CtrlName = "Home";
    18             ViewBag.CtrlName = CtrlName;
    19             ViewBag.Message = Message;
    20             ViewBag.OKAction = OKAction;
    21             ViewBag.CancelAction = CancelAction;
    22             return View();
    23         }
    24 
    25     }
    26 }
    View Code

    针对上述的Index的View为:

    Index.cshtml:

    @{
        ViewBag.Title = "温馨提示"; 
        Layout = "~/Views/Shared/_DlgLayout.cshtml";  
    }
    <h2>@ViewBag.Message</h2>
    <div data-inline="true">
    @Html.ActionLink("取消", (string)ViewBag.CancelAction, (string)ViewBag.CtrlName, null, new { @data_role = "button", @data_inline = "true" })
    @Html.ActionLink("确定", (string)ViewBag.OKAction, (string)ViewBag.CtrlName, null, new { @data_role = "button", @data_inline = "true" })  
    </div>
    View Code

    给上方的View做一个专用母版.复制默认模板_Layout.cshtml,,改名为: _DlgLayout.cshtml,内容如下:

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <title>@ViewBag.Title</title>
            <meta name="viewport" content="width=device-width" />
            <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
            @Styles.Render("~/Content/mobileCss", "~/Content/css")
            @Scripts.Render("~/bundles/modernizr")
        </head>
        <body>
            <div data-role="page" data-theme="b">
                <div data-role="header">          
                 <h1>@ViewBag.Title</h1>
               </div>
                 <div data-role="content">
                    @RenderBody()
                </div>
            </div>
    
            @Scripts.Render("~/bundles/jquery", "~/bundles/jquerymobile")
            @RenderSection("scripts", required: false)
        </body>
    </html>
    View Code

    修改Home/index.cshtml:

    @{
        ViewBag.Title = "Home Page";
    }
    
       <h2>@Html.ActionLink("访问关于1", "Index", "Dialog", new {OKAction ="About", CancelAction="Index",CtrlName="Home",Message = "打算访问关于吗?" }, new{@data_rel="dialog",@data_transition="pop"})</h2>
       <h2>@Html.ActionLink("访问联系方式", "Index", "Dialog", new { OKAction = "Contact", CancelAction = "Other", CtrlName="Home",Message = "打算访问联系方式吗?" }, new { @data_rel = "dialog", @data_transition = "pop" })</h2> 
     <h2> <a href="@Url.Action("Index", "Dialog",new { OKAction = "About", CancelAction = "Index", CtrlName = "Home", Message = "打算访问关于吗?"})" data-rel = "dialog", data-transition = "pop" > 访问关于2</a></h2>
    View Code

    在HomeController.cs文件中,增加一个Other Action以及相应的View Other,增加测试变化。

    演示效果图:

    演示代码下载->

  • 相关阅读:
    tomcat启动时报:IOException while loading persisted sessions: java.io.EOFException的解决方案
    Myeclispe 安装 SVN :
    Oracle数据库中SYS、SYSTEM、DBSNMP、SYSMAN四用户的区别
    转: Maven 仓库中添加Oracle JDBC驱动(11g)
    Ubuntu14.04的常用快捷键
    Ubuntu下常用的命令
    Ubuntu14.04 java环境配置
    主谓宾定状补
    Git的常用命令
    转:Android面试
  • 原文地址:https://www.cnblogs.com/exesoft/p/JQueryMobileDialog.html
Copyright © 2011-2022 走看看