partial-views

ASP.NET MVC partial views slow?

半腔热情 提交于 2019-12-03 11:56:03
问题 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 more conclusive investigation, but just in case there was somebody with similar issues or more insight, here is what I have so far. First, I should say that all results and measurements were done after multiple page loads and that I have set

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

半腔热情 提交于 2019-12-03 10:50:37
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. <section class="sidebar nested"> <h2>Nested Section</h2> <p>Lorem ipsum dolor sit amet, conse ctetur adipiscing elit. Maec enas id augue ac metu aliquam.</p> <p>Sed pharetra placerat est suscipit sagittis. Phasellus <a href="#">aliquam</a> males uada blandit. Donec adipiscing sem erat.</p> </section> I want to have a Partial View that is used like this: @Html.Partial("Path/To/Partial/View"){ <h2>Nested Section</h2> <p

ASP.NET MVC Strongly Typed Partial View, gives could not load type error

亡梦爱人 提交于 2019-12-03 10:14:13
I am attempting to create a strongly typed view with a "MVC View User Control" that is being rendered using Html.RenderPartial(). The top of my ascx file looks like this: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Collections.IEnumerable<string>>" %> There is nothing else on this page, currently. When I execute the app and load the page that renders this control, I get the following error: Could not load type 'System.Web.Mvc.ViewUserControl<System.Collections.IEnumerable<string>>'. So, then I simplified it: <%@ Control Language="C#" Inherits="System.Web.Mvc

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

淺唱寂寞╮ 提交于 2019-12-03 09:46:44
Just to distinguish between a view used inside a dialog or used in a foreach loop (customer details) ? You don't need an underscore. It's just a convention, and MVC is very keen on using conventions. Marius Schulz Mike Brind has put this nicely in the question Why does Razor _layout.cshtml have a leading underscore in file name? : Since layout pages in Web Pages are not intended to be served directly, they are prefixed with the underscore. And the Web Pages framework has been configured not to allow files with leading underscores in their names from being requested directly. Besides that, I

MVC3 Razor Partial view render does not include data- validation attributes

回眸只為那壹抹淺笑 提交于 2019-12-03 09:28:33
问题 I have a farily straight forward form that renders personal data as a partial view in the center of the form. I can not get client side validation to work on this form. I started chasing down the generate html and came up with the same model field rendered on a standard form and a partial view. I noticed that the input elements are correctly populated on the first call, @html.partial, the following only happens when the partialview is reloaded via an ajax request. First the header of my

Ruby on Rails: conditionally display a partial

拥有回忆 提交于 2019-12-03 09:21:15
I'm not sure if I'm doing the best approach here, but I have a block of data that I want to show after a search is done and to not be there at all before. First of all, there is nothing to show, and second the model it references is nil so it throws an exception. I placed this block in a partial template and added it the appropriate spot in my layout. Is there a way to cleanly render the partial conditionally? Is there a better way to approach this problem? Ruby allows you to do nice things like this: <%= render :partial => "foo/bar" if @conditions %> To make this a bit easier to read and

Rendering one mustache partial multiple times with different data

拈花ヽ惹草 提交于 2019-12-03 07:45:22
I have two objects that I want to render side by side. There is never a case where I will want to render more, or less than two. My model is setup like so: { obj1: {...}, obj2: {...} } Using mustache templates, I want to render each object using the same partial: <div> <h1>Object 1</h1> {{>objPartial}} </div> <div> <h1>Object 2</h1> {{>objPartial}} </div> However, mustache doesn't seem to support passing a context to the partial. Doing something like {{>objPartial obj1}} seems like it should be supported, but I can't find any documentation on setting a context for a partial. Is this sort of

MVC 3 Razor Form Post w/ Multiple Strongly Typed Partial Views Not Binding

巧了我就是萌 提交于 2019-12-03 07:25:25
I'm curious about whether the approach of using multiple strongly typed partials within a form that posts back to the partial containing View is the right MVC approach to doing things. The main View is bound with the following model with several other properties and data annotations omitted for brevity: public class AccountSetup : ViewModelBase { public bool TermsAccepted { get; set; } public UserLogin UserLogin { get; set; } public SecurityQuestions SecurityQuestions { get; set; } } public class UserLogin { public string LoginId { get; set; } public string Password { get; set; } } The markup

How to load views from a Class Library project?

南楼画角 提交于 2019-12-03 06:32:55
I tried to create a VirtualPathProvider and set the view as an embedded resource. class AssemblyResourceVirtualFile : VirtualFile { string path; public AssemblyResourceVirtualFile(string virtualPath) : base(virtualPath) { path = VirtualPathUtility.ToAppRelative(virtualPath); } public override System.IO.Stream Open() { string[] parts = path.Split('/'); string assemblyName = parts[2]; string resourceName = parts[3]; assemblyName = Path.Combine(HttpRuntime.BinDirectory, assemblyName); var assembly = Assembly.LoadFile(assemblyName); if (assembly != null) { return assembly.GetManifestResourceStream

Convert PartialView to HTML [duplicate]

a 夏天 提交于 2019-12-03 05:59:13
问题 This question already has answers here : MVC Return Partial View as JSON (3 answers) Closed 6 years ago . I am just wondering if it is possible to convert PartialView("_Product", model) to html so we can send it back with JSON ? return Json(result, JsonRequestBehavior.AllowGet); 回答1: Absolutely, put the following method in a shared controller or a helper class. It will return the rendered view in HTML, the usage is self explainatory: public static string RenderViewToString(ControllerContext