.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Disappearing partial view

Posted By:      Posted Date: August 26, 2010    Points: 0   Category :ASP.Net

I have a view that uses a partital view.  The partial view is invisible when the page loads.  The user then clicks a button and I use Html.RenderPartial to make the view appear.

There is a button in the partial view in which the use will click which should make the partial view disappear.  How do I make the partial view disappear?

Thanks for the help!

View Complete Post

More Related Resource Links

partial view, 2 controllers



This is my first visit to the forums, I hope someone here can help me


I'm writing a small webapplication for creating repair tickets and adding comments, really basic

now I'm writing this in MVC2

So I have 2 controllers, 1 HomeController that does everything related to the tickets (listing tickets, creating new ones, editing) and 1 controller for the comments

the edit view for the homecontroller contains a partial view for /comment/create

so /home/edit/ticketnumber can edit the title and status of the ticket on the left side of the screen, the right side of the screen contains the partial view for adding comments

this is done like this:

Html.Renderaction("Create", "Comment");

but if I look at the generated html code when running the app, both save buttons go to /home/edit/ticketnumber

so the comment is never saved.


I hope this makes sense and that someone can help me solve this

Rendering Partial view postback with data posted back and entire view context

This is the base Index.aspx view:<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> <%@ Import Namespace="LMWebUI.Components" %> <%@ Import Namespace="LMWebUI.Models" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <% Session["HasScripts"] = "false"; %> <% if (Utility.FixNull(Session["LoggedIn"],"false") == "false" ) {%> <% ViewData["Login"] = new PartialRequest ( new { controller = "Account", action = "LogIn" } ); ((PartialRequest)ViewData["Login"]).Invoke(ViewContext); %> <%} else {%> <div>Logged In Content here</div> <%}%> <script type="text/javascript"> LMx.init(); </script> </asp:Content> This is a helper class> that I found elsewhere, doesn't solve the problem, but still works to display the viewpublic class PartialRequest { public RouteValueDictionary RouteValues { get; private set; } public PartialRequest(object routeValues

Load View and Partial View (Master/Detail) with default parameter(s) ?

MVC newb.  Members view (index) that lists members that users can select to show a partial view in the same view with details for the selected member Uses jquery (Ajax.ActionLink) to call a partial view method in the members controller to then load the members detail section Works fine up to here....but I'd like to load the partial view with "member" details for a default or random member on initial load -- ie not through the Actionlink selection How do I invoke the partial view method on the initial load?  I'm sure this is basic stuff but still still getting my head around the mvc "way" Can someone point me to an example or explanation somewhere?  (not turning anything up on my searches thus far)   thanks in advance!!

Dynamic Javascript in Ajax Partial View

I have a partial view which uses Ajax.ActionLink to perform paging.  The AjaxOptions in the link identify the update target (a div on the main view) and some javascript to run OnSuccess (in the partial view).  The javascript must be in the partial view since there is some information in the partial view required to properly wire up the jQuery in the javascript.  This isn't working as expected.  The sample below is the minimum code to duplicate the behavior I am seeing: Controller: private static int count; // // GET: /Home/ public ActionResult Index() { ViewData["Test"] = count++; return View(); } [HttpPost] public ActionResult TestPartial() { ViewData["Test"] = count++; return PartialView(); } View:  <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Index</title> <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script> <script

Partial view and postbacks - undesired results

Sorry for the long post,I'm having problems after the postback. Each time I post back the changes made on the ui - I see the changes in the RateViewModel passed back, but the code populates each control in the table with these values - instead of the values from the ViewModel. What am I doing wrong?Object.public class CurrentAndFutureRate{        public int ParentID { get; set; }        public int ParentTypeID { get; set; }        public string ParentTypeDescription { get; set; }        public decimal CurrentRateValue { get; set; }        public DateTime CurrentStartDate { get; set; }        public DateTime? CurrentEndDate { get; set; }}View Modelspublic class CurrentAndFutureRateViewModel { public List<CurrentAndFutureRate> CurrentAndFutureRates { get; set; } } public class RateViewModel { public int ParentID { get; set; } public int ParentTypeID { get; set; } public int? RateID { get; set; } public decimal RateValue { get; set; } public DateTime StartDate { get; set; } public DateTime? EndDate { get; set; } } Master page renders a partial view(1) and the partial view displays a table

Ajax.BeginForm does not update/show the result in partial view


I have a view.On which i have two partial viewMy m ain is like this ->.(Note i am using Ajax.BeginForm here.)

<body >
<% using (Ajax.BeginForm("SearchRequests", new AjaxOptions { UpdateTargetId = "SearchRequestDIV" }))
   { %>
 <%-- <%using  (Html.BeginForm("SearchRequests", "PlanRequest", FormMethod.Post, new { enctype = "multipart/form-data" })){ %>--%>
    <div >
       <table class="tableborder" border="0" cellpadding="0" cellspacing="0">
            <%if (Model.MessageText !="" && Model.MessageText !="undefined") { %>
                <td >
                    <font color="red"><%=Html.Encode(Model.MessageText)%></font>
                   <% Html.RenderPartial("SearchRequestCriteria", Model); %>         
            <% if (Model.SearchResults.Count > 0)
               { %>
                 <div id="SearchRequestDIV">

Using a partial in a strongly typed view


I have an application that is going to allow a user to create records of type Customer and Seller that have one section in common, but other fields that are unique to their types.

Both of these types will have an address block for their create view.

If I have a strongly typed Customer or Seller view, how can I use the view partial (containing the address block) that I've created? I've tried creating a view model, but I don't know how to have the create page inherit the Customer model and the addressBlock partial inherit the addressBlockForm partial model...

Hopefully, this makes sense, and thank you for any help.

[Problem] MVC DropDownList Cascading Partial View


Hi, i'm trying to implement a cascading dropdownlist inside a partial view.

this is the code:

js function

function dropDownListCascade() {
    $('#idTipoAntecedente').change(function () {
        $.ajaxSetup({ cache: false });
        var selectedItem = $(this).val();
        if (selectedItem == "" || selectedItem == 0) {
            $("#idAntecedente").attr('disabled', 'enabled');

AJAX partial update of a partial view



I have an application which is using jQuery tabs. Each tab renders a partial view asynchronously, however some of these partial views need to also be partially updated. For example, one of them displays two tables of data, and one of the tables allows the user to filter the results, so I want to do a partial update of this one table, but I'm not sure how to accomplish this. I've been looking at Ajax.BeginForm, jQuery.post, and jQuery.load, but I'm not sure what the right approach is.

Thanks for any help. :)

MVC Partial View with Modal windows


Here is what I have as best as I can explain it.

I have a partial view called experience that is basic html markup.

I have a page that contains rows of records (experience records) and one of the columns in these rows is an "edit" link column.  When I click that link I want to pass the id of that row to a method that will package up the details of that row (linq query to the experience table using the passed in id).

(this is the important part) ...... I want the partial view (experience.ascx) along with its new Model containing the experience details to load in a modal dialog box rather than another page.

How can I accomplish this?

I'm new to all this so this may be was too little info ... if so let me know and I can expand.  Thanks in advance

Displaying partial view/View from another project in MVC


Hi guys,

i wonder if you know which is the best way (concerning performance) to display a view from another project.

I have a cms from which i create the contents. I have my website and may in the future work for other websites. 

I have two options so far:

1) Generating the content from my cms and using it as an embedded resource in the website

2)Using http handler, i get the content from the url and response.write it on the part of the page

Please let me know if there are better options?

Thank you for your help.

Partial View Updating Parent VIew ViewData?


From MSDN:

"When a partial view is instantiated, it gets its own copy of the ViewDataDictionary object that is available to the parent view. The partial view therefore has access to the data of the parent view. However, if the partial view updates the data, those updates affect only the partial view's ViewData object. The parent view's data is not changed.


Is there a common way around this?

For instance I have a View containing two Partial Views (User Controls) that source the same data from the Parents ViewData. The first Partial View is able to update (add/delete) certain data from the Parents View Data, however the second Partial View sources the same data but obviously isn't reflecting the changes owing to the above MSDN statement.


Cascading action for multiple partial view in one view



I would like to create one view for my CRUD actions.  The view contains 3 basic DIV updatetargets ("search form", "search result listing" and "action" (would be create,detail,edit,delete).  Basic flow would be: "Search" updates the "Search Result Listing", click on CRUD actions in listing would show partial view in "action". 

Problem how do I call to refresh the "Listing" after I do any add/update/delete without having user click search again?


<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Student Example</h2>
        <% using (Ajax.BeginForm("Search", "Student",
               new AjaxOptions { UpdateTargetId = "divSearchResult" }))
        { %>
        <%= Html.ValidationSummary(true) %>
            <legend>Student Search Criteria&

Rendering Area Partial view from External Dll



I am quite new to MVC and am gradually overcoming all my 'but WebForms can do that' issues but I still have one.

I wish to have components which I can deploy into an Area in order to keep things nice and tidy. This area will have a bunch of re-usable partial views like this.


I can render this MyAreaControl partial view fine in other Views inside that area but it fails when I try to render it from a not inside the area (e.g. view in the root of the site).

I am essentially using this syntax

<% Html.RenderPartial("MyAreaControl", new { area = "MyArea" }); %>
which seems to only look for this partial view inside the root Views folder, not the area one despite me specifying the area.
Is this a restriction of the system, a bug - or am I just doing it wrong.

Conditional Partial View Rendering


This is probably a no-brainer, but my head is not working today.

Just to get it work, I got a controller action that make use of a switch statement to decide which partial view to render, based on one of the members of the model passed in.  (Written by someone else for what it matter...I'm just cleaning up)

The viewmodel is overcomplicated, but that's not my decision right now and just have to live with it.

All partial's get rendered passing the same viewmodel, just a different partial get called.

 switch (model.something.code)
        case 1: 
          return PartialView("partial111", model);
		case 2:
			return PartialView("partial222", model);
		// ... and so it goes on...

Understanding Partial View in ASP.NET MVC

Partial View in ASP.NET MVC serves the same purpose as that of a User Control in ASP.NET Web Forms.

Truly Understanding View State

This article provides a detailed understanding of the ViewState.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend