html.renderpartial

ASP.NET MVC - Can a Partial View have a controller?

随声附和 提交于 2019-12-10 13:32:52
问题 When I'm in a View and I call @Html.RenderPartial("MyPartialView", MyObject) Can I set it up so that this partial view has a controller which is called when RenderPartial gets called? 回答1: Probably it will be better to use the RenderAction instead of the RenderPartial 回答2: You should gather all data necessary for the partial in the current controller action (which may use methods shared across other controllers and actions). If you really want a partial to be rendered using its own controller

Object reference not set to an instance of an object - Partial View

一曲冷凌霜 提交于 2019-11-29 17:59:55
I have a strongly typed partial view which is giving me "Object reference not set to an instance of an object" error when I launch the master view. I know I am not passing in any parameters yet, but is there a way to handle this error? Master View: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Test Form </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <div id="partial"> <% Html.RenderPartial(

Object reference not set to an instance of an object - Partial View

倾然丶 夕夏残阳落幕 提交于 2019-11-28 12:46:00
问题 I have a strongly typed partial view which is giving me "Object reference not set to an instance of an object" error when I launch the master view. I know I am not passing in any parameters yet, but is there a way to handle this error? Master View: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Test Form </asp:Content> <asp:Content ID=

asp.net MVC partial view controller action

跟風遠走 提交于 2019-11-26 18:19:37
I'm very new to web app development and I thought I would start with recent technology and so I'm trying to learn asp.net as-well as the MVC framework at once. This is probably a very simple question for you, MVC professionals. My question is should a partial view have an associated action, and if so, does this action get invoked whenever a normal page uses RenderPartial() on the partial view? While you can have an action that returns a partial view, you don't need an action to render a partial view. RenderPartial takes the partial view and renders it, using the given model and view data if

asp.net MVC partial view controller action

為{幸葍}努か 提交于 2019-11-26 06:15:00
问题 I\'m very new to web app development and I thought I would start with recent technology and so I\'m trying to learn asp.net as-well as the MVC framework at once. This is probably a very simple question for you, MVC professionals. My question is should a partial view have an associated action, and if so, does this action get invoked whenever a normal page uses RenderPartial() on the partial view? 回答1: While you can have an action that returns a partial view, you don't need an action to render