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

  • SEARCH
  • Home
  • 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 8733351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:37:51+00:00 2026-06-13T09:37:51+00:00

I am very new to asp.mvc 3. I am using kendoui and knockout for

  • 0

I am very new to asp.mvc 3. I am using kendoui and knockout for binding. My application looks like this sample:

ViewModel

public class MyViewModel
    {
        public MyViewModel()
        {
            Initialize();
        }

        public IEnumerable<string> MyOptions1 { get; set; }
        public string MyChoice1 { get; set; }

        public IEnumerable<string> MyOptions2 { get; set; }
        public string MyChoice2 { get; set; }

        private void Initialize()
        {
            MyOptions1 = new List<string>()
                             {
                                 "OptionA",
                                 "OptionB"
                             };

            MyOptions2 = new List<string>()
                             {
                                 "OptionC",
                                 "OptionD"
                             };
        }
    }

Index method of Home controller

public ActionResult Index()
        {
            return View();
        }

Index View:

<div id="optionsArea">
    <table>
        <tr>
            <td><label>Option1:</label></td>
            <td><input id="options1" data-bind="kendoDropDownList: { data: MyOptions1, value: MyChoice1 }" /></td>
        </tr>
        <tr>
            <td><label>Option2:</label></td>
            <td><input id="options2" data-bind="kendoDropDownList: { data: MyOptions2, value: MyChoice2 }" /></td>
        </tr>
    </table>
</div>

When Index view is loaded I am calling OptionsData method of controller which returns the populated MyViewModel as Json.

public ActionResult OptionsData()
        {
            var myModel = new MyViewModel();
            var jsonNetResult = new JsonNetResult
            {
                Formatting = Formatting.Indented,
                Data = myModel
            };

            return jsonNetResult;
        }

In javascript From MyViewModel I create populated javascript viewmodel viewModel with knockout observable properties and bind it to the div in the Index View.

$(function () {

    my = {

    }

    $.getJSON("/Home/OptionsData", function (data) {

        // create observable properties from MyViewModel
        my.viewModel = ko.mapping.fromJS(data);

        ko.applyBindings(my.viewModel, document.getElementById("optionsArea"));
    });
});

In my application I have many elements containing label and dropdown so I want to extract that part in something like a component and reuse it calling it with some parameters to replace the bindings. I read some articles and maybe the solution is to use partial views or custom HTML helpers so I can do something like this:

_OptionPartialView

<tr>
    <td><label>Option2:</label></td>
    <td><input data-bind="kendoDropDownList: { data: (parameter1), value: (parameter2) }" /></td>
</tr>

where somehow I want to replace parameter1 and parameter 2 when I call the partial in the Index View:

@Html.Partial("_OptionPartialView.cshtml", parameter1, parameter2);

or with helper method:

@Html.MyCustomHelper(..., parameter1, parameter2);

Then I will strongly bind my Index method to the Index view:

public ActionResult Index()
        {
            var myModel = new MyViewModel();
            return View(myModel);
        }

And my view will look something like this:

  @model MVC3Question.Models.MyViewModel

<div id="optionsArea">
    <table>
        @Html.Partial("_OptionPartialView.cshtml", Model.MyOptions1, Model.MyChoice1);
        @Html.Partial("_OptionPartialView.cshtml", Model.MyOptions2, Model.MyChoice2);
    </table>
</div>

My question is which is better in this situation Partial View or Custom Helper method and more important how do I implement them with the parameters having in mind the posted sample code. Any other approches or ideas are welcome. Thanks!

  • 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-06-13T09:37:52+00:00Added an answer on June 13, 2026 at 9:37 am

    In my opinion both methods are good.
    You can create a custom helper that takes two parameters like this:

    public static MvcHtmlString MyHtmlHelper(this HtmlHelper htmlHelper, string label, IEnumerable<string> option, string choise)
        {
            var html = new MvcHtmlString(String.Empty);
    
                html = MvcHtmlString.Create("<tr><td><label>" + label + ":</label></td><td><input data-bind=\"kendoDropDownList: { data: (" + option + "), value: (" + choise + ") }\" /></td></tr>");
    
    
            return html;
        }
    

    I would prefer this method because it will work without any change in your current code.

    If you want to use a partial view you will need to change your current model.

    public class MyViewModel
    {
        public MyViewModel()
        {
            MyOptions = new List<string();
        }
    
        public IEnumerable<string> MyOptions { get; set; }
        public string MyChoice { get; set; }
    }
    

    Then you can populate the model in your controller like this:

    public ActionResult Index()
        {
            var viewModels = new List<MyViewModel>();
            var myOptions1 = new List<string>()
                             {
                                 "OptionA",
                                 "OptionB"
                             };
    
            var myOptions2 = new List<string>()
                             {
                                 "OptionC",
                                 "OptionD"
                             };
            viewModels.Add(new MyViewModel{MyOptions = myOptions1});
            viewModels.Add(new MyViewModel{MyOptions = myOptions2});
            return View(viewModels);
        }
    

    After that you need to change your view like this:

        @model IList<MVC3Question.Models.MyViewModel>
    <div id="optionsArea">
        <table>
            @foreach(var viewModel in Model)
            {
                @Html.Partial("_OptionPartialView.cshtml", viewModel);
            }
        </table>
    </div>
    

    And finally create a partial view:

        @model Mvc3Question.Models.MyViewModel
    <tr>
        <td><label>Option2:</label></td>
        <td><input data-bind="kendoDropDownList: { data: (@Model.MyOptions), value: (@Model.MyChoice) }" /></td>
    </tr>
    

    I hope this helps.

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

Sidebar

Related Questions

I'm very new to ASP.NET MVC, so forgive me if this is something I
I am very new to ASP.NET and I am using the MVC 3 framework
I am relatively new to ASP.NET MVC, and am very impressed with the clarity
I am very new to asp classic application. The below code snippet is from
First some brief background: I have an existing ASP.NET MVC 1 application using Entity
I'm using the membership provider asp.net mvc 4. I'd like to get a list
I'm new to ASP.NET MVC and I'm trying to create a very simple blog
new to asp.net mvc (using v3 + razor) and am wondering how to best
I'm very new to ASP.NET MVC so I hope my question makes sense. I'm
I am very new to ASP.NET 4 and MVC 4. I have a requirement

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.