the object specified does not belong to a list - sharepoint-2007

I am having a problem to visualize the http://servername/SearchCenter/, it is showing the message:
Microsoft.SharePoint.SPException: the object specified does not belong to a list
and is showing the stack trace:
[SPException: the object specified does not belong to a list.]
Microsoft.SharePoint.SPWeb.GetItem(String strUrl, Boolean bFile, Boolean cacheRowsetAndId) +578
.
.
.
And is throwing this exception only when I am logged in.
I already got the project done, somebody just told me it could be a masterpage problem.
Whenever I open the subsite in the sharepoint designer SearchCenter the page SearchCenter/Pages/Default.aspx
it redirects to the root solution and open the _catalogs/Pages/searchmain.aspx
The code in the searchmain.aspx have the header.
<%# Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral"
meta:progid="SharePoint.WebPartPage.Document" %>
<%# Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="OSRVWC" Namespace="Microsoft.Office.Server.WebControls" Assembly="Microsoft.Office.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="SEARCHWC" Namespace="Microsoft.Office.Server.Search.WebControls" Assembly="Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
The same error occurs when I create a subsite, when you click create, it outputs:
The object specified does not belong to a list. at Microsoft.SharePoint.SPWeb.GetItem(String strUrl, Boolean bFile, Boolean cacheRowsetAndId)
at Microsoft.SharePoint.SPFile.get_Item()
at Microsoft.SharePoint.Publishing.PublishingWeb.GetPageLayoutCollectionFromStringMustCloseFileWeb(String pageLayoutUrls, Char[] delimiters, SPSite site)
at Microsoft.SharePoint.Publishing.Internal.AreaProvisioner.InitializePublishingWebDefaults()
It also appears on the first page.
! The specific object doesn't belong to a list.

Related

MVC3 ASPX view object does not contain definition

I started this project using MVC2, but changed to the MVC3 dll.
I have an Asset entity. In the controller I have the Details ActionResult defined like this:
EDIT: (Put the correct controller code.)
public ActionResult Details(int id)
{
using (var db = new AssetsContainer())
{
return View(db.Assets.Find(id));
}
}
My Details.aspx page is defined this way:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CITracker.Models.Asset>" %>
<%# Import Namespace="CITracker.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Details
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Details</h2>
<fieldset>
<legend>Fields</legend>
<div class="display-label">Id</div>
<div class="display-field"><%: Model.Id %></div>
I get this error:
CS1061: 'object' does not contain a definition for 'Id' and no extension method 'Id' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Any ideas why this was working with MVC2 but fails with MVC3? I don't get develop time errors, but I do get runtime errors.
I am not sure, but looks like this is the problem. You are passing a List to the view
return View(db.Assets.ToList());
but your Inherits says
Inherits="System.Web.Mvc.ViewPage<CITracker.Models.Asset>" instead of
Inherits="System.Web.Mvc.ViewPage<IEnumerable<CITracker.Models.Asset>>"
And also since your model is now a IEnumerable, you can not do a simple Model.Id instead it should be Model[0].Id (or what ever ith elemnt you choose or you do a foreach)
This is an old question, but I ran into the same problem converting some MVC 2 code to MVC 3. A simple configuration problem to look for is making sure you have this app setting in your config:
<appSettings>
<add key="enableSimpleMembership" value="false" />
</appSettings>
See this thread for more info.

ASP.NET MVC - Html.RenderPartial issues

I have a usercontrol named "LoginUserControl.ascx" which I have placed in a master page.
Header of "LoginUserControl.ascx"
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MultiTechnologyWeb.Models.loginmodel>" %>
Then I used the below code to show the usercontrol in the masterpage.
<% Html.RenderPartial("LoginUserControl"); %>
On first run the page "index" is loaded.
Notice the header of the "index" page, no model is specified. Thus page load successfully
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MT.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
Now I click on the link to open register.aspx. I got the below error
The model item passed into the dictionary is of type 'MultiTechnologyWeb.Models.registermodel', but this dictionary requires a model item of type 'MultiTechnologyWeb.Models.loginmodel'.
Header of "register.aspx" page
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MT.Master" Inherits="System.Web.Mvc.ViewPage<MultiTechnologyWeb.Models.registermodel>" %>
So to my understanding model is being interchanged, so anybody can please help me on how to resolve this issue
More Explanation.............LATEST
I have debug, i know that the crash is occuring after the actionresult for register is finished execution.
Code below is for actionresult "register"
public ActionResult register()
{
registermodel model;
//some code here
return View("register",model);
}
So i'm just returning one type of model that is "registermodel", Would it be possible to return another model such as "loginmodel" by using a list or array to return multiple models in the same view.
You should use <% Html.RenderAction("Logon","Account"); %> in your MasterPage instead of using RenderPartial and in this action you just return the login partial you want to use in the header
public ActionResult Logon(){
// do your stuff
return PartialView("LoginUserControl");
}
By this way you could pass the loginmodel to the LogInPartial and pass registermodel to the register page
Please not that RenderAction and RenderPartial are not the same.
RenderPartial will render only the view. While RenderAction will make a new MVC roundtrip, by making a new instance of the controller etc and returning the result.
To solve your issue you could pass in the MultiTechnologyWeb.Models.loginmodel where you call <% Html.RenderPartial("LoginUserControl"); %>. It would look like this:
<% Html.RenderPartial("LoginUserControl", new MultiTechnologyWeb.Models.loginmodel()); %>
Or:
<% Html.RenderPartial("LoginUserControl", Model.LoginModel); %>
If you're not wanting to send a model to your partial view, which I've wanted to do in the past, you do have to at least pass something to the RenderPartial method.
This was the only method I could find that allowed me to now have to pass a model. I tried passing null and it continued to pass the parent model
<% Html.RenderPartial("LoginUserControl", new ViewDataDictionary()); %>

Referencing an attribute for a simple tag and Struts 2.x

I am writing a simple tag which contains 4 attributes like so:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# attribute name="menuName" description="Name of Major Menu" required="true" %>
<%# attribute name="menuSize" description="Number of Items In Menu" required="true" type="java.lang.Integer" %>
<%# attribute name="menuImage" description="Icon for Image" required="true" %>
<%# attribute name="menuNumber" description="Order of Positioning" required="true" %>
There is a point within a Struts 2 tag that I need to make reference to one of these attributes like so:
<s:set name="it" value="%{#application['tools'][${menuName}]}" />
So you see I am doing a lookup in the OGNL expression based upon what the menu name which was passed in. From all the examples I see, EL is the common way of referencing the attribute menuName, but in Struts 2.x EL is disabled for security reasons.
Is there a way to reference the attribute I need to reference. I really do not want to consider any solution which involves me going to previous versions of jstl or struts.
<s:set name="menuName" value="%{#attr['menuName']}" />
<s:set name="it" value="%{#application['tools'][#menuName]}" />
Never knew about the #attr before, how neat

Add property to an ASP.NET MVC 2 ViewUserControl

I have created a ViewUserControl in my ASP.NET MVC 2 project. This ViewUserControl serves as the general page-header for all views in the project.
How can I add a custom property on ViewUserControls, accessible from views using that control?..:
<%# Register
Src="../Shared/Header.ascx"
TagName="Header"
TagPrefix="uc" %>
<uc:Header
runat="server"
ID="ucHeader"
MenuItemHighlighted="Menuitem.FrontPage" /> <!-- custom property, here -->
Instead of creating user controls ala WebForms way I would suggest you the following:
Create a strongly typed user control Header.ascx:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<div><%: Model %></div>
And then simply include it in your pages:
<% Html.RenderPartial("~/Views/Shared/Header.ascx", "some value"); %>
In my example the user control is strongly typed to string but you could've used any custom type.

HtmlHelper missing?

I'm trying to create an Html Helper, by creating a static class as follows:
public static string Crumbs(this HtmlHelper helper, params string[] args) where T : class
{
// ... rest of code goes here.
}
And I'm invoking it like this:
<% Html.Crumbs(
Html.ActionLink("Home", "Index", "Home"),
Html.ActionLink("Lists", "Index", "User"),
Html.Encode(Model.List.Name)); %>
However, the view does not compile, as I get the following compilation error:
CS1061:
'System.Web.Mvc.HtmlHelper'
does not contain a definition for
'Crumbs' and no extension method
'Crumbs' accepting a first argument of
type
'System.Web.Mvc.HtmlHelper'
could be found (are you missing a
using directive or an assembly
reference?)
I don't get it. None of the documentation that I have mentions that you need to register the namespace of the static class anywhere. What am I doing wrong?
You need to import the namespace of your extension in you view or in web.config.
In web.config:
<pages>
<namespaces>
<add namespace="MyExtensions.Namespace"/>
In your view:
<%# Import Namespace="MyExtensions.Namespace" %>
You need to register the namespace in web.config
<system.web>
<pages>
<namespaces>
<add namespace="X.Y.Z"/>
</namespaces>
</pages>
</system.web>
Make sure you put your helper in namespace (any) that is referenced in web.config or the page itself (Import Namespace).

Resources