0

My partial view isn't being loaded. Please find my code snippets, I can't figure out what is wrong. Help please.

The error message is:

c:MvcUI\Views\Project\Details.ascx(42): error CS1950: The best overloaded Add method 'System.Web.Mvc.ViewDataDictionary.Add(System.Collections.Generic.KeyValuePair)' for the collection initializer

I am having In my view:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcUI.Models.ProjectModel>" %><%Html.RenderPartial("LabelsDetails", Model.Categories, new ViewDataDictionary{"labelsName", labelsName }); %> 

My partialView

<%@ Control language="C#"Inherits="System.Web.Mvc.ViewUserControl<Models.ProjectModel>" %> <%int count = 0; %> <%var labelsName = ViewData["labelsName"];%> <%if (Model!=null) {%> <%if (!String.IsNullOrEmpty(Model.Name)) {%> <li> <%: Html.Hidden((labelsName)+".Index", count.ToString())%> <%: Html.TextBox((labelsName)+"[" + (count) + "].Name", Model.Name, new { Style = "width:280px" })%> <%: Html.Hidden((labelsName)+"[" + (count++) + "].ID", Model.ID, new { Style = "width:280px" })%> <input type="button" value = "Delete"/> </li> <%} %> <%} %> <li> <%: Html.Hidden((labelsName) + ".Index", count.ToString())%> <%: Html.TextBox((labelsName) + "[" + (count) + "].Name", "", new { Style = "width:280px" })%> <%: Html.Hidden((labelsName) + "[" + (count++) + "].ID", 0, new { Style = "width:280px" })%> <input type="button" value= "Add" /> </li> 

My projectModel

public class Label { public String Name { get; set; } public int ID { get; set; } } public List<Label> Categories { get; set; } 

2 Answers 2

1

The syntax you are using to initialize the ViewDataDictionary is wrong. You need two {. Try like this:

<% Html.RenderPartial( "LabelsDetails", Model.Categories, new ViewDataDictionary {{ "labelsName", labelsName }} ); %> 
Sign up to request clarification or add additional context in comments.

6 Comments

On which line are you getting this exception?
it`s showing the error on <% Html.RenderPartial( "LabelsDetails", Model.Categories, new ViewDataDictionary {{ "labelsName", labelsName }} ); %>
Thanks, but now i`l having error message: c:\Code\MvcUI\Views\Project\LabelsDetails.ascx(7): error CS1061: MvcUI.Models.Label' does not contain a definition for 'Id' and no extension method 'Id' accepting a first argument of type 'MvcUI.Models.Label' could be found (are you missing a using – user281180
What's on line 7 in c:\Code\MvcUI\Views\Project\LabelsDetails.ascx?
Please find LabelsDetails above, as my partialview
|
0

Dariv code for renderpartial was helpful but there was an error on the partial view inherits which can be found on

http://sokhanh03.spaces.live.com/blog/cns!78F088CCD824626B!832.entry

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.