如何打开在asp.net MVC使用jQuery模态弹出的局部视图? [英] How to open a partial view by using jquery modal popup in asp.net MVC?
问题描述
我有我想通过使用JQuery模态弹出打开的局部视图。这是没有问题,而对于开放的新纪录看法,但我想将数据传递给编辑这个局部视图。什么是实现这个你最好的方法是什么?
I have a partial view which I want to open by using JQuery Modal Popup. There is no problem while opening the view for a new record but I want to pass data to this partial view for edit. What is your best way to implement this?
先谢谢了。
推荐答案
我有这方面的工作以及我目前的项目。
I have this working well in my current project.
一个局部视图使用继承控制标记,就像一个完整的视图不强类型的模型对象的数据类型。
A partial view uses the Inherits control markup just like a full view does to strongly type the Model object to a datatype.
下面是通过AJAX调用返回,并把一个div内的局部视图的一个很简单的例子。此partialview的目的是为了显示通过传递给它的文本消息。
Here is a very simple example of a partial view that is returned via a ajax call and put inside a div. The purpose of this partialview is to display a text message that is passed through to it.
LiteralMessage.ascx
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<!-- LiteralMessage.ascx start -->
<%= Model %>
<!-- LiteralMessage.ascx end -->
控制器方法
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ReturnId(int id)
{
return PartialView("LiteralMessage", string.Format("Hello world! Id: {0}", id));
}
请注意,在部分页面视图可以是任意复杂的对象。
Note that in the partial page view can be any complex object.
我希望这有助于!
编辑:并因此被列为jQuery的为好,用这个作为你的AJAX的成功事件。 (这是假设你的对话与MyDialogMessage的标识内容DIV的对话DIV中与MyDialog的ID)
and because this is listed as jQuery as well, use this as your ajax's success event. (This is assuming your dialog has a content DIV with an Id of MyDialogMessage inside a dialog DIV with an Id of MyDialog)
// executes when $.post is complete
function doSuccess(result)
{
$('div#MyDialog div#MyDialogMessage').html(result);
//show dialog
$('div#MyDialog').dialog('open');
}
这篇关于如何打开在asp.net MVC使用jQuery模态弹出的局部视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!