MVC Razor #section doesn't understand Scripts - asp.net-mvc

I have:
VS 2013
MVC 5.2.2
Razor 3.2.2
Let me know if there's anything else you need to know.
This problem only happens on one view page.
I have a View with all HTML tags closed off properly
It's your standard view...
#model MyNameSpace.Models.Inquiry
#{
var hasFormSetup = Model != null && Model.FormSetup != null && Model.FormSetup.Count > 0;
if (hasFormSetup)
{
ViewBag.Title = Model.FormSetup[0].InquiryValue;
}
Layout = "~/Views/Shared/_LayoutInquiry.cshtml";
}
<style scoped>
ul {
list-style-type: none;
}
</style>
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
<div class="container" style="margin-top: 5px;">
etc...
</div>
<div class="container" >
etc...
</div>
}
#section Scripts
{
<script type="text/javascript">
$(document).ready(function () {
etc...
});
</script>
}
but...
on the line
#section Scripts
Resharper reports: "Cannot resolve section Scripts"
When I run, I get the exception:
Source: System.Web.WebPages
Target: Void VerifyRenderedBodyOrSections()
Type: HttpException
Message: The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_LayoutInquiry.cshtml": "Scripts".
Stack: at System.Web.WebPages.WebPageBase.VerifyRenderedBodyOrSections()
at System.Web.WebPages.WebPageBase.PopContext()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.WebPages.WebPageBase.<>c__DisplayClass3.<RenderPageCore>b__2(TextWriter writer)
at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
at System.Web.WebPages.WebPageBase.Write(HelperResult result)
at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
at System.Web.WebPages.WebPageBase.PopContext()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
etc...
No other page has this issue.
Any ideas as to how I can fix this?

The exception message says:
The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_LayoutInquiry.cshtml": "Scripts".
This suggests that your _LayoutInquiry.cshtml page does not setup a placeholder for a Scripts section. You can do this by adding #RenderSection("Scripts", false) to your layout page in the appropriate location, where the false indicates that views may optionally supply this section.
Now, when your view renders, the contents of #section Scripts { ... } in your view will be rendered into the location of the #RenderSection("Scripts", false) call in your layout page.

I had this same issue but using Rider instead of VS. The code was actually legit, but some cache got in the way.
So the solution was to "Invalidate and Restart" - found in File > Invalidate caches...

For others that may end up here. Everything is working OK but ReSharper complains about Section and Styles missing.
Our case was that we had _Layout.cshtml and _Layout.Mobile.cshtml in the shared folder.

Related

Server could not create ASP.reporting_reportvalueprediction_aspx

I am binding RDLC Report viewer in my project but getting this error
Server could not create ASP.reporting_reportvalueprediction_aspx.
Exception Details: System.InvalidOperationException: Server could not create ASP.reporting_reportvalueprediction_aspx.
Stack Trace:
[InvalidOperationException: Server could not create ASP.reporting_reportvalueprediction_aspx.]
__ASP.FastObjectFactory_app_web_sxcnkdic.Create_ASP_reporting_reportvalueprediction_aspx() +192
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +31
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +104
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path) +39
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +386
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163
`<%# Page Language="vb" Debug="true" AutoEventWireup="false" CodeBehind="ReportValuePrediction.aspx.vb" Inherits="TimiWeb.ReportValuePrediction" %>
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server">
</asp:ScriptManager>
<div>
<rsweb:ReportViewer ID="rptReportViewer" runat="server" Width="100%" Height="700px">
</rsweb:ReportViewer>
</div>
</form>
</body>
</html>`
**
I write these VB code to bind report**
Imports Microsoft.Reporting.WebForms
Public Class ReportValuePrediction
Inherits System.Web.UI.Page
Private _dt As DataTable
Public Sub New(ByVal dt As DataTable)
_dt = dt
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim rep As LocalReport = rptReportViewer.LocalReport
rep.ReportPath = "/Reporting/ValuePrediction.rdlc"
Dim rds As New ReportDataSource()
If _dt.Rows.Count > 0 Then
rds.Name = "ValuePredictionDS"
rds.Value = _dt
rep.DataSources.Add(rds)
End If
End If
End Sub
End Class

Is this HtmlHelper extension overkill?

I've implemented a custom html helper extension method to render a partial view into my razor page and I'm concerned that the method I've used is "too heavy"...
I want to use a common spinner across my web project. The spinner I'm using requires a number of elements:
<div class="panel-spinner-container">
<div class="sk-spinner sk-spinner-cube-grid">
<div class="sk-cube"></div>
<div class="sk-cube"></div>
<div class="sk-cube"></div>
<div class="sk-cube"></div>
<div class="sk-cube"></div>
<div class="sk-cube"></div>
<div class="sk-cube"></div>
<div class="sk-cube"></div>
<div class="sk-cube"></div>
</div>
<div class="panel-spinner-msg"><p>loading...</p></div>
</div>
Rather than including this in razor code every time I want a spinner, I figured I'd toss it into an html helper method, so I could do this:
<div>
#Html.PanelSpinner()
</div>
I created a partial view for this which just contains the divs from above, and an html helper extension method:
public static MvcHtmlString PanelSpinner(this HtmlHelper html) {
var controllerContext = html.ViewContext.Controller.ControllerContext;
var viewData = html.ViewData;
var tempData = html.ViewContext.TempData;
using (var stringWriter = new System.IO.StringWriter()) {
var viewResult = ViewEngines.Engines.FindPartialView(controllerContext, "PanelSpinner");
var viewContext = new ViewContext(controllerContext, viewResult.View, viewData, tempData, stringWriter);
viewResult.View.Render(viewContext, stringWriter);
var stringResult = stringWriter.GetStringBuilder().ToString();
return new MvcHtmlString(stringResult);
}
}
This seems like an awful lot of processing required to render a spinner. What is the performance overhead on this type of method? Is it normal to use a helper for this type of scenario, or am I overkilling this? Is there a better (more performant) way to do this?
I very much like the ease of use but am concerned about performance (e.g., I could just use #Html.RenderPartial(...), but then I have to remember the name of the spinner partial, etc. The helper method wrapper is so much easier to use)
To render a partial view using an extension method, you can make use of the built in Partial() method of HtmlHelper. It can simply be
public static MvcHtmlString PanelSpinner(this HtmlHelper html)
{
return html.Partial("PanelSpinner");
}
Note: You need to include using System.Web.Mvc.Html;

What is the MVC equivalent of Find Control?

In ASP.NET web forms it is possible to modify page controls from the master page. For example, on a page "/Sample" I could set TextBox1 as readonly by doing the following.
//Site.master.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Path.ToUpper().Contains("/SAMPLE"))
{
TextBox TB = MainContent.FindControl("TextBox1") as TextBox;
TB.ReadOnly = true;
}
}
The question is... Is there an equivalent way to do this in an MVC application that uses a SiteLayout?
Background: We have purchased an MVC application and have access to modify the
source code. We need to customize the behaviors on some of the pages. It
will only be used by a few dozen people so a performance hit won't really be noticeable. If this was a Web Forms
application we would use the above method. However this application
is written with MVC and it is making our web form programmer (me) confused on how best to proceed. Customizing numerous pages is going to be a headache when
we have to patch the software. Having all the changes in one central location
would be easier to manage going forward. How can you have one place where you can customize other pages programmatically in MVC?
There is no MVC equivalent for FindControl, since views are built in a single operation, where ASP.NET controls are built up and modified over several different events. You don't need to find the control, you specify all of its attributes as it is built.
The rough equivalent to an ASP.NET control (at least in this context) is an HTML helper. HTML helpers are implemented as static extension methods, which allows them to be shared between views and perform some actions as the view is loaded.
using System.Web.Mvc;
using System.Web.Mvc.Html;
public static class MyExtensions
{
public static MvcHtmlString TextBox1(this HtmlHelper helper, string name)
{
if (helper.ViewContext.HttpContext.Request.Path.ToUpper().Contains("/SAMPLE"))
{
return InputExtensions.TextBox(helper, name, null, new { #readonly = "readonly" });
}
return InputExtensions.TextBox(helper, name);
}
}
Usage
~/Views/Shared/_Layout.cshtml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>#ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
</head>
<body>
<header>
<div class="content-wrapper">
<div class="float-left">
<p class="site-title">#Html.ActionLink("your logo here", "Index", "Home")</p>
</div>
<div class="float-right">
<section id="login">
#Html.Partial("_LoginPartial")
</section>
<nav>
<ul id="menu">
<li>#Html.ActionLink("Home", "Index", "Home")</li>
<li>#Html.ActionLink("About", "About", "Home")</li>
<li>#Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</nav>
</div>
</div>
</header>
<div id="body">
#RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
#* Render custom HTML Helper *#
#Html.TextBox1("test")
#RenderBody()
</section>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>© #DateTime.Now.Year - My ASP.NET MVC Application</p>
</div>
</div>
</footer>
#Scripts.Render("~/bundles/jquery")
#RenderSection("scripts", required: false)
</body>
</html>
Note that it is also possible to put the logic directly in the view, but then you cannot reuse logic in other views and it makes your view look cluttered.
As for reading the data back out of a textbox, you need to put it within a <form> tag so it can be posted to a controller action method, which is the rough equivalent of a submit button click event. Unlike ASP.NET, MVC supports multiple <form> tags so you don't have to mix your logic for different actions on the page.
Your question is very broad. But generally, if you want to provide read only rendering for your controls in your razor views based on some conditions, you can try the below approach.
You should add a IsReadOnly property to your view model and use that to render the control the way you wanted.
public class CreateCustomerVM
{
public bool IsReadOnly {set;get;}
//Other properties goes here
public string Email { set; get; }
public string Name { set; get; }
}
In your Action method set the IsReadOnly propery value based on your condition.
public ActionResult Index()
{
var vm=new CreateCustomerVM();
//Set the value based on your condition
vm.IsReadOnly=true;
return View(vm);
}
And in your view , you use the IsReadOnly property to determine whether you want to display a readonly control or not.
#model YourNameSpaceGoesHere.CreateCustomerVM
#using (Html.BeginForm())
{
#Html.TextBoxFor(m => m.Email)
if(Model.IsReadOnly)
{
#Html.TextBoxFor(m => m.Name, new { #readonly = "readonly" })
}
else
{
#Html.TextBoxFor(m => m.Name)
}
<input type="submit"/>
}

Creating Some thing #using (Html.BeginForm()) Helpers

In Asp.net MVC3 when you write below code , it generates wrapping html itself
#using (Html.BeginForm()) {
#Html.ValidationMessageFor(model => model.Text)
}
It generates codes in below format,
<form method="post" action="/Feeds">
<!-- Fields Here -->
</form>
My question in #using (Html.BeginForm()) automatically adds <form> tag at beginning and end, how can i create something like that of my own.
I am looking for some thing like below
#using (Html.BeginMYCUSTOMDIV())
{
I am text inside div
}
Expected Generated Output
<div class="customDivClass">
I am text inside div
</div>
Something along the lines:
public class MyDiv : IDisposable
{
private readonly TextWriter _writer;
public MyDiv(TextWriter writer)
{
_writer = writer;
}
public void Dispose()
{
_writer.WriteLine("</div>");
}
}
public static class MyExtensions
{
public static MyDiv BeginMYCUSTOMDIV(this HtmlHelper htmlHelper)
{
var div = new TagBuilder("div");
div.AddCssClass("customDivClass");
htmlHelper.ViewContext.Writer.WriteLine(div.ToString(TagRenderMode.StartTag));
return new MyDiv(htmlHelper.ViewContext.Writer);
}
}
and in the view:
#using (Html.BeginMYCUSTOMDIV())
{
<span>Hello</span>
}
generates:
<div class="customDivClass">
<span>Hello</span>
</div>
If I'm not mistaken, Html.BeginForm() returns an IDisposable object. When used in the using block, the object's Disposemethod is called, which is the responsible to write the closing tag to the output.
how does using HtmlHelper.BeginForm() work?
Html.BeginForm() type of extension

MVC asp.net PartialView causing No Parameterless constructor error?

Having an issue with an MVC 2.0 application partial view that all of the sudden when accessed and stuff is actually in the ViewData, the dreaded No parameterless Constructor error. I Have followed the code as much as I can and I'm getting no where. Here is my code:
Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel;
using CINet.Areas.CatalystSearch.Models.Interfaces;
using CINet.Areas.CatalystSearch.Models.Repository;
using CINet.Areas.CatalystSearch.Models.Entities;
namespace CINet.Areas.CatalystSearch.Controllers
{
public class CatalystSearchController : Controller
{
// private SqlCatalystRepository _catalystItemRepository;
private ICatalystRepository _catalystInterface;
public int PageSize = 10; // Regulates size of page
#region CONSTRUCTOR
/// <summary>
/// Constructor which sets the passed repository to the local current
/// repository
/// </summary>
/// <param name="catalystRepository">Interface repository for controller</param>
public CatalystSearchController()
{
}
#endregion
#region DEFAULT VIEW
public ViewResult List([DefaultValue("")] string manufactureName, [DefaultValue("")] string manufacturePartNumber, [DefaultValue("")] string description, [DefaultValue(1)] int page)
{
IQueryable<CatalystItem> query = null;
CatalystFilter userFilter = new CatalystFilter();
int totalItems = 0;
// Be sure that the manufacture drop down has been selected
if (manufactureName != "")
{
// Set up CatalystFilter
userFilter.Manufacture = manufactureName;
userFilter.DescriptionFilter = description;
userFilter.ManufacturePartNumberFilter = manufacturePartNumber;
// connection string for SQL
string connString = "Data Source=se-cinet-dev;Initial Catalog=cinet;User ID=sa;Password=Carouse1";
// Get interface
_catalystInterface = new CatalystRepository(connString);
// Collects data from SQL repository and updates private local copy
// _catalystItemRepository = new SqlCatalystRepository(connString);
// Fills with list of Catalystitems based on filter.
query = _catalystInterface.GetCatalystItems(userFilter, page, PageSize);
// query = _catalystItemRepository.GetItems(userFilter, page, PageSize);
// Returns int of total items in list
totalItems = _catalystInterface.GetTotalOfItems(userFilter);
// totalItems = _catalystItemRepository.GetTotalOfItems(userFilter);
// Set up view model for passing to View
var viewModel = new CatalystModel
{
catalystItems = query.ToList(),
catalystFilter = userFilter,
/* Pass Paging properties to model*/
PagingInfo = new PagingInfo
{
CurrentPage = page,
ItemsPerPage = PageSize,
TotalItems = totalItems
},
ManufactureName = manufactureName
};
// View Data to be passed to SearchView
ViewData["catalystItems"] = viewModel;
return View(viewModel);
}
else
{
var viewModel = new CatalystModel();
return View(viewModel);
}
}
#endregion
#region SEARCH VIEW
/// <summary>
/// Partial View used to display results from controller
/// </summary>
/// <param name="model"> model passed via ViewData from List View</param>
/// <returns></returns>
[ChildActionOnly]
public ViewResult SearchView(CatalystModel model)
{
return View(model);
}
#endregion
}
}
listView:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CINet.Areas.CatalystSearch.Models.Entities.CatalystModel>" %>
<%# Import Namespace="CINet.Areas.CatalystSearch.HtmlHelpers" %>
<%# Import Namespace="CINet.Areas.CatalystSearch.Models" %>
<%# Import Namespace="CINet.Areas.CatalystSearch.Models.Interfaces" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<div>
<center>
<strong>
<%= Html.ValidationSummary("Please fill out required Fields") %></strong>
<h1>Catalyst Search Provider</h1>
<hr />
<%-- "Search","Catalyst" --%>
<%
using (Html.BeginForm())
{ %>
<table border="1">
<tr>
<td>Enter Description (optional):</td>
<td>
<%: Html.TextBoxFor(x=>x.Description) %>
</td>
</tr>
<tr>
<td>Enter Part Number (optional):</td>
<td>
<%: Html.TextBoxFor(x=>x.ManufacturePartNumber) %>
</td>
</tr>
<tr>
<td>Choose Manufacture:
</td>
<td>
<%: Html.DropDownListFor(x => x.ManufactureName, Model.GetAllManufactures()) %>
<%-- <%: Html.DropDownList("ManufactureName", Model.GetAllManufactures(),"Choose Item")%> --%>
</td>
</tr>
<tr>
<td>
&nbsp
</td>
<td>
<input type="submit" name="Search" value="Search" />
</td>
</tr>
</table>
<% } Html.EndForm(); %>
<!-- RENDERS PARTIAL VIEW TO DISPLAY GRID WITH SEARCH RESULTS -->
<% Html.RenderAction("SearchView", ViewData["catalystItems"]); %>
<br />
</center>
</div>
<div class="pager">
<% if (Model.PagingInfo != null)
{ %>
<%: Html.PageLinks(Model.PagingInfo, x => Url.Action("List", new { page = x, manufactureName = Model.catalystFilter.Manufacture, description = Model.catalystFilter.DescriptionFilter, manufacturePartNumber = Model.catalystFilter.ManufacturePartNumberFilter }))%>
<% } %>
</div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
SearchView:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CINet.Areas.CatalystSearch.Models.Entities.CatalystModel>" %>
<%# Import Namespace="CINet.Areas.CatalystSearch.HtmlHelpers" %>
<%# Import Namespace="CINet.Areas.CatalystSearch.Models" %>
<div>
<% if (Model.catalystItems != null)
{ %>
<table class="CatalystTableSpacer">
<tr>
<td>
Contract Price
</td>
<td>
Description
</td>
<td>
Manufacture Name
</td>
<td>
Manufacture Part Number
</td>
<td>
MSRP Price
</td>
<td>
Quantity Available
</td>
</tr>
<% foreach (var items in Model.catalystItems)
{%>
<tr>
<td>
<%: items.ContractPrice%>
</td>
<td>
<%: items.Description%>
</td>
<td>
<%: items.ManufactureName%>
</td>
<td>
<%: items.ManufacturePartNumber%>
</td>
<td>
<%: items.MSRPrice%>
</td>
<td>
<%: items.QuantityAvailable%>
</td>
</tr>
<% }
}
%>
</table>
</div>
CatalystModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CINet.Areas.CatalystSearch.Models.Entities;
using System.ComponentModel.DataAnnotations;
using CINet.Areas.CatalystSearch.Models.Repository;
using CINet.Areas.CatalystSearch.Models.Interfaces;
namespace CINet.Areas.CatalystSearch.Models.Entities
{
public class CatalystModel
{
#region PRIVATE FIELDS
private string _connectionString = "Data Source=se-cinet-dev;Initial Catalog=cinet;User ID=sa;Password=Carouse1"; // connection string for SQL
private ICatalystRepository _repository = null;
#endregion
#region PUBLIC PROPERTIES
public IList<CatalystItem> catalystItems { get; set; }
public PagingInfo PagingInfo { get; set; }
public CatalystFilter catalystFilter { get; set; }
public SelectList Manufactures { get; set; }
public SelectList Categories { get; set; }
[Required]
public string ManufactureName { get; set; }
public string Description { get; set; }
public string ManufacturePartNumber { get; set; }
#endregion
#region CONSTRUCTOR
/// <summary>
/// Constructor instantiates SQL DB Connection
/// </summary>
public CatalystModel()
{
_repository = new CatalystRepository(_connectionString);
// Manufactures = GetAllManufactures();
}
#endregion
#region PUBLIC GET LISTS
/// <summary>
/// Returns ALL Manufactures in Database
/// </summary>
/// <returns></returns>
public SelectList GetAllManufactures()
{
SelectList manufactureNameSelectList;
List<Manufacture> manufactureTempList = new List<Manufacture>();
// Get List from DB
manufactureTempList = _repository.GetManufactureList();
// PUSH LIST INTO SELECT LIST
manufactureNameSelectList = new SelectList(manufactureTempList, "ManufactureName", "ManufactureName");
return manufactureNameSelectList;
}
#endregion
}
}
The error happens in the ListView calling the SearchView:
<% Html.RenderAction("SearchView", ViewData["catalystItems"]); %>
Any help??
Actual Error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
No parameterless constructor defined for this object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
Source Error:
Line 53: <!-- RENDERS PARTIAL VIEW TO DISPLAY GRID WITH SEARCH RESULTS -->
Line 54: <%-- <% Html.RenderPartial("SearchView", ViewData["catalystItems"]); %>
Line 55: --%> <% Html.RenderAction("SearchView", ViewData["catalystItems"]); %>
Line 56:
Line 57: <br />
Source File: c:\Users\gcoleman\Documents\Source Code\Sandbox\Jonathan Henk\MVC\CINet\CINet\Areas\CatalystSearch\Views\CatalystSearch\List.aspx Line: 55
Stack Trace:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
System.Activator.CreateInstance(Type type) +6
System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +403
System.Web.Mvc.DefaultModelBinder.BindSimpleModel(ControllerContext controllerContext, ModelBindingContext bindingContext, ValueProviderResult valueProviderResult) +544
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +479
System.Web.Mvc.DefaultModelBinder.GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder) +45
System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +658
System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +147
System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model) +98
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +2504
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +548
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +475
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +181
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
System.Web.Mvc.Controller.ExecuteCore() +136
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +111
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +65
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +52
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.Mvc.<>c__DisplayClassa.<EndProcessRequest>b__9() +44
System.Web.Mvc.<>c__DisplayClass4.<Wrap>b__3() +34
System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +76
System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Action action) +113
System.Web.Mvc.ServerExecuteHttpHandlerAsyncWrapper.EndProcessRequest(IAsyncResult result) +124
System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1072
[HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +3058371
System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +77
System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +28
System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +22
System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +766
System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +98
System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, Object routeValues) +65
ASP.areas_catalystsearch_views_catalystsearch_list_aspx.__RenderContent1(HtmlTextWriter __w, Control parameterContainer) in c:\Users\gcoleman\Documents\Source Code\Sandbox\Jonathan Henk\MVC\CINet\CINet\Areas\CatalystSearch\Views\CatalystSearch\List.aspx:55
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
ASP.views_shared_site_master.__Renderform1(HtmlTextWriter __w, Control parameterContainer) in c:\Users\gcoleman\Documents\Source Code\Sandbox\Jonathan Henk\MVC\CINet\CINet\Views\Shared\Site.Master:26
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +8820669
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +31
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +53
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +56
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
Your problem is that the CatalystModel class doesn't have a default constructor so the default model binder cannot instantiate it here:
[ChildActionOnly]
public ViewResult SearchView(CatalystModel model)
{
return View(model);
}
This being said having such a child controller action that you are invoking like this:
<% Html.RenderAction("SearchView", ViewData["catalystItems"]); %>
is totally useless and bring strictly no value.
Why don't you render the partial directly:
<% Html.RenderPartial("SearchView", ViewData["catalystItems"]); %>
You should also read the Haacked blog post to better understand the differences between RenderAction and RenderPartial.
Or if you really (for some cryptic reason) have controller actions that take some models which do not have default constructors as action parameters you will need to write a custom model binder for this type and specify which of your custom constructors should be used to instantiate it and what values should be passed to it of course.
Try this:
<% Html.RenderAction("SearchView", new { model = ViewData["catalystItems"] }); %>

Resources