How to open partial view using jQuery modal popup in asp.net MVC?

I have a partial view that I want to open using jQuery Modal Popup. There is no problem opening a view for a new record, but I want to transfer the data to this partial view for editing. What is your best way to implement this?

Thanks in advance.

+3
source share
2 answers

It works well for me in my current project.

The partial view uses the Inherit control add-in , as well as the full view, to strongly apply the Model object to the data type.

, ajax div. - .

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));
}

, .

, !

:, jQuery, ajax success. (, DIV MyDialogMessage DIV MyDialog)

// executes when $.post is complete
function doSuccess(result)
{
    $('div#MyDialog div#MyDialogMessage').html(result);
    //show dialog
    $('div#MyDialog').dialog('open');
}
+3

, . Colorbox ( IFRAME), jQuery.

+1

Source: https://habr.com/ru/post/1719880/


All Articles