Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1047235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:16:10+00:00 2026-05-16T16:16:10+00:00

I would like to pass more than one parameter to the partial view. With

  • 0

I would like to pass more than one parameter to the partial view. With the following

 <% Html.RenderPartial("Details", Model.test, new ViewDataDictionary { { "labelName", "Values1" }, {"header", "Header1"}, {"header2", "Header2"}}); %> 

code, I am having error message

) missing.

What is wrong?


<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<MvcUI.Models.Label>>" %>

 <%var label = ViewData["labelName"];%>
 <%int count = 0; %>


            <%if (Model!=null) {%>           
               <% foreach (var model in Model){ %>     


                    <%if (!String.IsNullOrEmpty(model.Name))                   
                   {%>
                    <li>
                          <%: Html.Hidden((label)+".Index", count.ToString())%>
                          <%: Html.TextBox((label)+"[" + (count) + "].Name", model.Name, new { Style = "width:280px" })%>
                          <%: Html.Hidden((label)+"[" + (count++) + "].ID", model.ID, new { Style = "width:280px" })%>
                        <input type="button" value = "Delete"/>
                    </li>
                    <%}
                     %>
                 <%} %>

                <% } %> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:16:10+00:00Added an answer on May 16, 2026 at 4:16 pm

    Instead of using the ViewDataDictionary can’t you simply add the required values to the model:

    public class MyModel
    {
        public string Test { get; set; }
        public string LabelName { get; set; }
        public string Header { get; set; }
        public string Header2 { get; set; }
    }
    

    and then simply:

    <% Html.RenderPartial("Details", Model); %> 
    

    Other than that there’s nothing wrong with your syntax. The error you are getting is from somewhere else:

    <% Html.RenderPartial(
        "Details", 
        Model.test, 
        new ViewDataDictionary { 
            { "labelName", "Values1" }, 
            { "header", "Header1" }, 
            { "header2", "Header2" }
        }
    ); %>
    

    UPDATE:

    Now that you’ve shown your code, let me suggest you a cleaner approach using editor templates.

    Start by defining a model:

    public class MyModel
    {
        public IEnumerable<Label> Labels { get; set; }
    }
    
    public class Label
    {
        public string ID { get; set; }
        public string Name { get; set; }
    }
    

    Then a controller which will fill this model:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = new MyModel
            {
                Labels = new[] 
                {
                    new Label { ID = "l1", Name = "Label 1" },
                    new Label { ID = "l2", Name = "Label 2" },
                    new Label { ID = "l3", Name = "Label 3" }
                }
            };
            return View(model);
        }
    }
    

    Then the view (~/Views/Home/Index.aspx):

    <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SomeNs.Models.MyModel>" %>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <ul>
            <%: Html.EditorFor(x => x.Labels) %>
        </ul>
    </asp:Content>
    

    and finally the editor template (~/Views/Home/EditorTemplates/Label.ascx):

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SomeNs.Models.Label>" %>
    <li>
        <%: Html.HiddenFor(x => x.ID) %>
        <%: Html.TextBoxFor(x => x.Name) %>
        <input type="button" value="Delete" />
    </li>
    

    As you can see, using editor templates you no longer have to worry about naming the inputs, maintaining and incrementing indexes, writing loops, all those error prone things are handled by the framework automagically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.