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.

2664 questions
1058
votes
13 answers

Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

In ASP.NET MVC, what is the difference between: Html.Partial and Html.RenderPartial Html.Action and Html.RenderAction
Ghooti Farangi
  • 19,228
  • 14
  • 42
  • 61
413
votes
22 answers

How to dynamically change header based on AngularJS partial view?

I am using ng-view to include AngularJS partial views, and I want to update the page title and h1 header tags based on the included view. These are out of scope of the partial view controllers though, and so I can't figure out how to bind them to…
Michael Low
  • 23,431
  • 15
  • 75
  • 115
343
votes
25 answers

Injecting content into specific sections from a partial view ASP.NET MVC 3 with Razor View Engine

I have this section defined in my _Layout.cshtml @RenderSection("Scripts", false) I can easily use it from a view: @section Scripts { @*Stuff comes here*@ } What I'm struggling with is how to get some content injected inside this section…
tugberk
  • 54,046
  • 58
  • 232
  • 321
166
votes
4 answers

How can I pass parameters to a partial view in mvc 4

I have a link like this: Profile and when I click on this it will call this partial page: @{ switch ((string)ViewBag.Details) { case "Profile": { …
neel
  • 4,583
  • 12
  • 37
  • 63
99
votes
4 answers

Rails: confused about syntax for passing locals to partials

Understanding Rails "magic" with regards to rendering partials (and passing locals into them). Why does this work: <%= render "rabbits/form" %> And this work: <%= render "rabbits/form", :parent => @warren, :flash => flash %> but this does not…
Meltemi
  • 36,348
  • 48
  • 182
  • 274
81
votes
7 answers

How to include a partial view inside a webform

Some site I'm programming is using both ASP.NET MVC and WebForms. I have a partial view and I want to include this inside a webform. The partial view has some code that has to be processed in the server, so using Response.WriteFile don't work. It…
eKek0
  • 21,835
  • 24
  • 87
  • 117
77
votes
2 answers

Using partial views in ASP.net MVC 4

I have recently started playing around with ASP.net MVC (4), but I can't wrap my head around this one issue I'm having. I'm sure it's easy when you know it. I'm essentially trying to do the the following in my Index view: List the current items in…
Espen S.
  • 877
  • 1
  • 8
  • 10
70
votes
9 answers

Include JavaScript file in partial views

I am wondering what the best practice is for including javascript files inside partial views. Once rendered this will end up as a js include tag in the middle of my page's html. From my point of view this isn't a nice way of doing this. They belong…
Peter
  • 13,204
  • 14
  • 66
  • 109
70
votes
5 answers

Is it OK to put JavaScript in Partial Views

I’m working on the web app where the main page contains two parts: the constant block which is always visible and the info-block made up by one of 3 partial views. Each of the partial views appears as a result of AJAX request and is loaded just once…
Tomy
  • 753
  • 1
  • 5
  • 11
67
votes
11 answers

Getting index value on razor foreach

I'm iterating a List in a razor foreach loop in my view which renders a partial. In the partial I'm rendering a single record for which I want to have 4 in a row in my view. I have a css class for the two end columns so need to determine in the…
lloydphillips
  • 2,595
  • 2
  • 30
  • 56
65
votes
5 answers

Render Partial View from other controller

Is there a way to render inside my view of controller A a partial view from other controller B? Edit: I wrote a partial view that is good for only two controllers and I don't want to copy it to their both Views folder. I want The partial view to…
gdoron is supporting Monica
  • 136,782
  • 49
  • 273
  • 342
64
votes
6 answers

Create controller for partial view in ASP.NET MVC

How can I create an individual controller and model for a partial view? I want to be able to place this partial view any where on the site so it needs it's own controller. I am current rendering the partial as so @Html.Partial("_Testimonials")
brenjt
  • 15,133
  • 11
  • 74
  • 114
54
votes
9 answers

How to Render Partial View into a String

I have the following code: public ActionResult SomeAction() { return new JsonpResult { Data = new { Widget = "some partial html for the widget" } }; } I'd like to modify it so that I could have public ActionResult…
DaveDev
  • 38,095
  • 68
  • 199
  • 359
53
votes
2 answers

What does the j function in Rails do?

I just came across a blog that mentions a j function in Rails. They were using it to do ajax style page updates. $('#cart').html("<%=j render @cart %>"); I get they are using partials to render the cart partial, but whats the point of j? I've…
Tyler DeWitt
  • 22,191
  • 36
  • 108
  • 189
45
votes
2 answers

Unobtrusive validation not working on dynamically-added partial view

I am currently facing a problem with validation after dynamically adding content. I have a view strongly typed to a model (Order). This Order can have many items. The model looks something like the following: public class Order { [Key] …
1
2 3
99 100