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 8550067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:51:58+00:00 2026-06-11T13:51:58+00:00

The following EditorTemplate does not work how I would like; <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<SHP.Models.BusinessUnitSelected>

  • 0

The following EditorTemplate does not work how I would like;

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SHP.Models.BusinessUnitSelected>" %>

<tr>
    <td><%: Model.BusinessUnit.BusinessUnitName %></td>
    <td><%: Html.CheckBoxFor(model => model.Selected, 
        new { onclick = "SaveSelection(" + Model.EmployeeId + ", " + Model.BusinessUnit.BusinessUnitId + ", " + Convert.ToInt32(Model.Selected) + ", " + this.ClientID + ")" }) %>
    </td>
</tr>

I want to get the Id of the Checkbox, and this.ClientID fails to do that.
This EditorTemplate forms a grid of rows within a table.
When a person clicks on the checkbox, the SaveSelection javascript is performed;

    function SaveSelection(employeeId, businessUnitId, selectedFlag, elementId) {
        //var tempFlag = selectedFlag === "0";

        var element = document.getElementById(elementId);
        if (selectedFlag === null) {
            selectedFlag = true;
        } else {
            selectedFlag = !selectedFlag;
        }

        var url = '<%: Url.Action("AddBusinessUnitForEmployee", "DataService")%>';
        dataService.saveSelection(employeeId, businessUnitId, selectedFlag, elementId, SavedSetting, url);
    }

    SavedSetting = function(data) {
        $('#' + data.ElementId).after('<span class="error">' + data.Message + '</span>');
    };

What I want is to display a message next to the checkbox after the server call.
So how do I do this?
Upticks will be awarded for advice on how I can improve this code.

  • 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-11T13:51:59+00:00Added an answer on June 11, 2026 at 1:51 pm

    You could use HTML5 data-* attributes:

    <%@ Control 
        Language="C#" 
        Inherits="System.Web.Mvc.ViewUserControl<SHP.Models.BusinessUnitSelected>" 
    %>
    
    <tr>
        <td><%: Model.BusinessUnit.BusinessUnitName %></td>
        <td>
            <%= Html.CheckBoxFor(
                x => x.Selected,
                new { 
                    data_url = Url.Action("AddBusinessUnitForEmployee", "DataService"),
                    data_employeeId = Model.EmployeeId,
                    data_businessUnitId = Model.BusinessUnit.BusinessUnitId
                }
           ) %>
        </td>
    </tr>
    

    and then in a separate javascript file unobtrusively subscribe to the .click() event of those checkboxes and then fetch the required information from the data-* attributes:

    $(function() {
        $('tr input[type="checkbox"]').click(function() {
            var elementId = $(this).attr('id');
            var url = $(this).data('url');
            var employeeId = $(this).data('employeeId');
            var businessUnitId = $(this).data('businessUnitId');
            var selectedFlag = !$(this).is(':checked');
    
            dataService.saveSelection(
                employeeId, 
                businessUnitId, 
                selectedFlag, 
                elementId, 
                SavedSetting, 
                url
            );
        });
    });
    

    Remark: I can’t exactly remember if ASP.NET MVC 2 supported the data_ syntax in order to rewrite it to data- syntax in the generated markup. This is defintely supported in ASP.NET MVC 3 and later. If it doesn’t work for you, you could use a different overload taking a RouteValueDictionary:

    <%= Html.CheckBoxFor(
        x => x.Selected,
        new RouteValueDictionary
        {
            { "data-url", Url.Action("AddBusinessUnitForEmployee", "DataService") },
            { "data-employeeId", Model.EmployeeId },
            { "data-businessUnitId", Model.BusinessUnit.BusinessUnitId }
        }
    ) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an editor template (Views/Shared/EditorTemplates/HORDER.ascx) which inherits System.Web.Mvc.ViewUserControl<CCOK2.Models.HORDER> My viewmodel has a one-to-many
Not getting updates in MVC View following a post method Hi, Here's my controller
Following code takes like 2500 milliseconds on an i7-*3.4 GHz windows-7 64-bit computer to
Following are the simple statements in the irb shell. What does nil in the
Following on from my previous question: Simple inner join in linq How would I
I've been using Editor-Templates in the past like this, by applying the following data
Following the way Rob does it, I have the classes that are generated by
I have to display my decimal as 00.00. I have the following EditorTemplate @model
i have the following situation. I am developing a MVC 3 asp.net application. I
I have the following working system and looking for ways to make it DRY:

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.