Questions tagged [partial-views]

User control in Asp.Net Web forms that is used for code re-usability. Partial views helps us to reduce code duplication . Reusable views like as Header and Footer views .

Partial view is like a regular view with a file extension .cshtml. We can use partial views in a situation where we need a header, footer reused for an MVC web application. We can say that it’s like a user control concept in ASP.NET.

2715 questions
27
votes
4 answers

getting the values from a nested complex object that is passed to a partial view

I have a ViewModel that has a complex object as one of its members. The complex object has 4 properties (all strings). I'm trying to create a re-usable partial view where I can pass in the complex object and have it generate the html with html…
Blair Holmes
  • 1,521
  • 2
  • 22
  • 35
26
votes
4 answers

Updating PartialView mvc 4

Ey! How I could refresh a Partial View with data out of the Model? First time, when the page loads it's working properly, but not when I call it from the Action. The structure I've created looks like: Anywhere in my View: @{…
Mario Levrero
  • 3,345
  • 4
  • 26
  • 57
24
votes
3 answers

Using Html.RenderPartial() in ascx files

I'm trying to use Html.RenderPartial in acsx file and I'm getting an error: Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'RenderPartial' but appears to have an extension method by that name.…
takayoshi
  • 2,789
  • 5
  • 36
  • 56
24
votes
3 answers

Returning an EditorTemplate as a PartialView in an Action Result

I have a model similar to this: public class myModel { public ClassA ObjectA {get; set;} public ClassB ObjectB {get; set;} } In my main view, I have tags similar to this:
<%=Html.EditorFor(m =>…
Mike Therien
  • 928
  • 3
  • 10
  • 25
23
votes
3 answers

Rendering the field name in an EditorTemplate (rendered through EditorFor())

I'm currently building the Admin back-end for a website in ASP.NET MVC. In an ASP.NET MVC application, I've started using the 'EditorFor' helper method like so:

<%= Html.LabelFor(c =>…

Jonathan
  • 32,202
  • 38
  • 137
  • 208
22
votes
4 answers

Passing anonymous objects from a view to a partial view

I understand from various other related questions here and here among others, that you can't pass anonymously typed objects from the controller to the view because anonymous types are defined with the Internal accessor. The View and Controller code…
Andy McCluggage
  • 37,618
  • 18
  • 59
  • 69
22
votes
1 answer

How can I add a view path to Rails's partial rendering lookup?

I'd like to have the following directory structure: views/ app1/ users/_user.html.erb users/index.html.erb app2/ users/index.html.erb shared/ users/_user.html.erb users/index.html.erb In my view, I'd call #…
22
votes
2 answers

How to handle model state errors in ajax-invoked controller action that returns a PartialView

I have a POST controller action that returns a partial view. Everything seems really easy. but. I load it using $.ajax(), setting type as html. But when my model validation fails I thought I should just throw an error with model state errors. But my…
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
22
votes
3 answers

Why do I need an underscore for partial views in asp.net mvc

Just to distinguish between a view used inside a dialog or used in a foreach loop (customer details) ?
Elisabeth
  • 20,496
  • 52
  • 200
  • 321
21
votes
2 answers

Asp:net MVC 3: @Html.EditorFor a subcollection of my model in a template?

I've been stuck a long time to edit a subcollection of my model, the collection of the model was coming null. I finally found a solution, but I find it a little dirty: First my tests datas: Model object: public class ContainerObject { …
J4N
  • 19,480
  • 39
  • 187
  • 340
21
votes
6 answers

Disable caching on a partial view in MVC 3

I have an issue with a partial View being cached when it shouldn't be. This partial View is used to display the Logon/Logoff on a page. It uses the simple code below to figure out which link to display @if(Request.IsAuthenticated) {
SimpleUser
  • 1,341
  • 2
  • 16
  • 36
21
votes
2 answers

A controller action which returns a partial view inserts the logon page when authorization fails

I have a view that loads a partial view from a controller action using jQuery. The controller action is decorated with the Authorize attribute and if the user has timed out when that action is called intead of being redirected to the proper LogOn…
21
votes
3 answers

ASP.NET MVC partial views slow?

I just happen to check the performance of an ASP.NET MVC application we are building. I was going to insert a partial view into a loop, and just out of curiosity I checked how long it took to render the page. The result was not good. I need to do…
Jan Zich
  • 14,993
  • 18
  • 61
  • 73
20
votes
2 answers

How can I pass HTML content to a Partial View in MVC-Razor like a "for" block

I'm using Chromatron theme for an admin panel in my application. There is a sidebar gadget that has HTML content and with a little CSS trick it can be shown completely different.
Achilles
  • 1,554
  • 1
  • 28
  • 36
19
votes
2 answers

Html.RenderPartial and Ajax.BeginForm -> Submit is called twice

I have the following index view: @model BoringStore.ViewModels.ProductIndexViewModel @{ ViewBag.Title = "Index"; }

Produkte

@{ Html.RenderPartial("Create", new BoringStore.Models.Product()); }