简体   繁体   English

MVC:如何在div中显示视图

[英]MVC: How to have a View display from within a div

In my MVC project indide one of my views I have some JQuery that pops up a dialog whos content is defined within a tag 在我的MVC项目中,我的一个视图中有一个JQuery,它弹出一个对话框,其内容是在标记中定义的

Is there a way that I can ensure the contents of the is a View/PartialView which is populated from my controler along the lines of: 有没有一种方法可以确保的内容是View / PartialView,它是从我的控制器沿以下行填充的:

    public ActionResult PopulateDivContent()
    {
        MyBusinessEntity entity = GetEntity();
        return PartialView("SingleRow", MyBusinessEntity);
    }

How would I go about doing this? 我将如何去做呢?

I have some jQuery that loads a partial view into a page. 我有一些jQuery,可将部分视图加载到页面中。 The partial view is an upload form for attaching images. 局部视图是用于附加图像的上传表单。

Here is the js/jQuery: 这是js / jQuery:

            function addAnImageClick() {
                // hide this
                $("a#addImage").hide();
                // show loading gif
                $("img.addAnImageLoadingGif").show();
                // invoke ajax get
                $.get("/FileManager/GetUploadForm", 
                    { postUrl: "/Announcements/UploadImageToAnnouncement", modelID: <% =Model.ID %>, multipleFiles: false }, 
                    function(data) {
                    // show upload form
                    $("div#imageUploader").html(data);
                    $("div#imageUploader").show();
                    // hide loading gif
                    $("img.addAnImageLoadingGif").hide();
                });
            }

As you can see i hide the link that the user clicks to initiate this function, then show the loading gif for UI feedback, then invoke the ajax call to the controller. 如您所见,我隐藏了用户单击以启动此功能的链接,然后显示UI反馈的加载gif,然后调用对控制器的ajax调用。 I also pass some values to the action. 我还将一些价值传递给行动。 Once the response is back i load the content into the div with this line: $("div#imageUploader").html(data); 一旦响应返回,我就使用以下行将内容加载到div中: $("div#imageUploader").html(data); . The div was hidden with css display:none which then i show and finish by removing the loading gif from visibility. div用css display:none隐藏,然后我通过删除可见性中的gif来显示并完成。

Here is the action: 这是动作:

    //
    // GET: /FileManager/GetUploadForm/?uploadAction=actionName&modelID=1234&multipleFiles=true
    public class GetUploadFormDTO
    {
        public string PostUrl { get; set; }
        public int ModelID { get; set; }
        public bool MultipleFiles { get; set; }
    }
    [KsisAuthorize()]
    public ActionResult GetUploadForm(string postUrl, string modelID, string multipleFiles)
    {
        GetUploadFormDTO model =
            new GetUploadFormDTO()
            {
                PostUrl = postUrl,
                ModelID = Convert.ToInt32(modelID),
                MultipleFiles = Convert.ToBoolean(multipleFiles)
            };

        return PartialView("UploadFormPartial", model);
    }

Hope this helps. 希望这可以帮助。 :D :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在视图中从多个表显示 - How to Display From Multiple Tables From Within View 我如何使用razor mvc构建html字符串以显示在div中? - How do I build up an html string to display within a div using razor mvc? 从mvc返回对象作为json,如何显示在视图上 - returning object as json from mvc, how to display on the view 如何在View MVC4中显示相关表中的数据? - How to display data from related tables in View MVC4? 如何从控制器显示列表元素以查看[MVC5] - How to display elements of list from controller to view [MVC5] 如何使用mvc从本地文件夹显示图像 - how to display images from local folder to view using mvc 如何让byte []显示为视图上div的背景图像(C#,ASP.NET,MVC) - How to get byte[] to display as a background image for a div on a view (C#, ASP.NET, MVC) MVVMCross 如何在视图中显示视图 - MVVMCross How to display a view within a view 当在 ASP.NET Core 5 MVC 中显示表中的数据时,视图 model 没有任何显示,尽管表有多行? - When display data from table in ASP.NET Core 5 MVC on view model nothing display although table have multiple rows? 在数据库的MVC 4视图中显示有限的数据 - Display limited data in mvc 4 view from database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM