English 中文(简体)
模块弹出时的负负部分视图
原标题:load partial view in to a modal popup

我正和MVC3 C#4.0合作

我创造了一个片面的观点。

我页面上有一个按钮, 当我点击这个按钮时, 我想能够将部分视图装入一个模式弹出。 我想最好的方法就是通过 javascript 来做到这一点, 我在应用程序中使用 jQuery 。

任何指点 如何我可以做到这一点?

最佳回答

您可以使用 “http://jqueryui.com/demos/dialog/>jQuery 界面对话框

所以首先写一个控制器 :

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

    public ActionResult Modal()
    {
        return PartialView();
    }
}

a modal.cshtml 部分,其中将包含您想要在模式中显示的部分标记:

<div>This is the partial view</div>

以及 Index.cshtml 视图中包含按钮, 当单击时该按钮将把部分显示为模式 :

<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $( .modal ).click(function () {
            $( <div/> ).appendTo( body ).dialog({
                close: function (event, ui) {
                    dialog.remove();
                },
                modal: true
            }).load(this.href, {});

            return false;            
        });
    });
</script>

@Html.ActionLink("show modal", "modal", null, new { @class = "modal" })

显然,在这个例子中,我已经把直接的脚本放到索引视图中,但是在真正的应用中,这些脚本将进入单独的javarciming文件。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签