Error using Orchard.Search.ViewModels;

Topics: Troubleshooting
Oct 2, 2013 at 6:24 PM
Edited Oct 4, 2013 at 6:23 PM
Hi,

Upgrading a website from 1.5.1 to 1.7 and using VS2010 with full source solution and theme as a seperate project.

Everything fine till a runtime problem on localhost relating to the search box in the header view.

____Cannot perform runtime binding on a null reference

Line 14: @Html.TextBox("q", (SearchViewModel)Model.ViewModel.Query


I think this relates to the themes web.config for the System.Web.WebPages.Razor - any ideas where the reference should be changed to stop this problem?

The 1.7 source requires System.Web.WebPages v2 (changing to v1 this causes a chain of errors) - the old source 1.5.1 was using System.Web.WebPages 1.

I have changed the theme to reference v2.

Warning 5 C:\inetpub\wwwroot\stmarytwick.org.uk\Orchard.Source.1.7.1\src\Orchard.Web\Themes\StMarysChurch\Views\SearchForm.cshtml: ASP.NET runtime error:

[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection.


Type A originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.


Type B originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. C:\inetpub\wwwroot\stmarytwick.org.uk\Orchard.Source.1.7.1\src\Orchard.Web\Themes\StMarysChurch\Views\SearchForm.cshtml 1 1 StMarysChurchTheme
FIXED

CHANGING BELOW LINE AND UPDATING WEB.CONFIG IN THE THEME TO USE RAZOR .10 AS WEB.CONFIG IN ORCHARD.WEB THEMES FOLDER



@using (Html.BeginForm("index", "search", new { area = "Orchard.Search" }, FormMethod.Get, new { @class = "search-form" }))
{
// create text box using HtmlHelper method (name|value|html attributes collection) - for custom use underscore eg data_provide="typeahead" = data-provide="typeahead" 
//   @Html.TextBox("q", (SearchViewModel)Model.ViewModel.Query, new { @class = "search-input", @id = "q", title = "Search " + Client, placeholder = "Search " + Client, @size = "15", @autofocus="autofocus", @data_provide = "typeahead", @data_items = "4" });


__ @Html.TextBox("q", String.Empty, new { @class = "search-input", @id = "q", title = "Search " + Client, placeholder = "Search " + Client, @size = "15", @autofocus = "autofocus", @data_provide = "typeahead", @data_items = "4" });__
  <button type="submit" value="" class="search-submit"></button>
}