最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net mvc - Adding Partial view with javascript - Stack Overflow

programmeradmin1浏览0评论

When I click the button I want a new copy of the "View_Name" to be added to the page. How would I do this in javascipt? Below is what the page looks like to start with.

<fieldset>
 <legend>Some Form</legend>

@{ Html.RenderPartial("Partiale"); }
<input type="button" value="Add new Item" />
</fieldset

When I click the button I want a new copy of the "View_Name" to be added to the page. How would I do this in javascipt? Below is what the page looks like to start with.

<fieldset>
 <legend>Some Form</legend>

@{ Html.RenderPartial("Partiale"); }
<input type="button" value="Add new Item" />
</fieldset
Share Improve this question asked Jul 30, 2013 at 0:39 user751651user751651 3
  • You would load the view using ajax. – Jasen Commented Jul 30, 2013 at 1:03
  • Can you post your Model and your Controller Action? – ataravati Commented Jul 30, 2013 at 3:15
  • The controller is only returning the view a above and there is no model right now. The view is only html right now – user751651 Commented Jul 30, 2013 at 3:17
Add a ment  | 

1 Answer 1

Reset to default 5

See below example

HTML:

<fieldset>
 <legend>Some Form</legend>

<div id="divPartial">
</div>

<input type="button" id="mybutton" value="Add new Item" />
</fieldset> 

Jquery:

    <script src="//ajax.googleapis./ajax/libs/jquery/1.10.1/jquery.min.js"></script> 
<script>
    $(document).ready(function () {

            $("#mybutton").click(function () {

                var url = "/Item/FilteredItemGallery/"; 

                $.ajax({
                    url: url,
                    cache: false,
                    type: "POST",
                    success: function (data) {


                        $('#divPartial').html(data);
                        /* little fade in effect */
                        $('#divPartial').fadeIn('fast');

                    },
                    error: function (reponse) {
                        alert("error : " + reponse);
                    }
                });

            });

        });
</script>

Controller Action:

public ActionResult FilteredItemGallery()
        {

            return PartialView("GalleryPartial");//return your partial view here
        }
发布评论

评论列表(0)

  1. 暂无评论