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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:14:37+00:00 2026-05-29T10:14:37+00:00

I have setup Knockoutjs to dynamically create an editable list of values using the

  • 0

I have setup Knockoutjs to dynamically create an editable list of values using the following code:

       var requirementModel = function() {
        var self = this;
        self.requirementtypes = ko.observableArray(@Html.Interpret(Model.requirementtypes));
        self.requirementid = ko.observable(@Html.Interpret(Model.requirementid));
        self.AddRequirementType = function() {
            self.requirementtypes.push({
                requirementtypeid: null,
                number: "",
                requirementid: 0
            });
        };
        self.RemoveType = function(Type) {
            self.requirementtypes.remove(Type);
        };
        self.hookUpValidation = function() {
            $.validator.unobtrusive.parseDynamicContent('.dynamicData');
        };
    };
    var viewModel = new requirementModel();
    ko.applyBindings(viewModel);

With html:

 <div class="small-box dynamicData"  data-bind="template:{ name: 'requirementType-template', foreach: requirementtypes, afterRender:$root.hookUpValidation }" ></div>
<button data-bind='click: AddType'>Add Type</button>

I have hooked up validation for dynamic data using the code recommended on stackoverflow.

When I post back to the server (I’m not using JSON just form post) I can do more complex validation and if something fails I can use ModelState.AddModelError(“input field name”, “I pity the fool that broke this”); This works perfectly with either strongly type or @Html.ValidationMessage(“input field name”) for non dynamic fields

However I can’t find a way to hook Server Side Model Error to dynamic content.

I have the span tags that work with the client side and they work perfectly. However they aren’t getting hooked into data returned after serverside validation fails and return page. Any idea how to acheive this?

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-05-29T10:14:38+00:00Added an answer on May 29, 2026 at 10:14 am

    I’ve just finished coding this for my current work project. I cannot post the code for propitiatory rules. Like your comment above says, there isn’t an elegant way. I will describe the steps that we took to display our error messages.

    First, modify your dynamically generated html so that each has the equivalent code to MVC3 @Html.ValidationFor(…) control. Next each dynamic control needs to have an id field that you can use to locate control to add error message to.

    Steps I took were, starting after the controller receives the ajax data for validation –

    1. Validate the received data model

    2. Create a class to return the results that looks like this

      Class AjaxResults{
          bool success {get; set;);
          object returnedData {get; set;);
      }
      
    3. If model validates, return AjaxResults with success = true and returnedData = “validated data model”

    4. If models does not validate then

    5. Collect all the errors into a list of pairs. Where key = fieldID and value = “the error message”.
    6. return AjaxResults with success = false and returnedData = “list of errors”

    7. After client receives the AjaxResults object

    8. If success = true, process result normally.

    9. If success = false, iterate through list highlighting the fields with the error and displaying the error message.

    In the last step, you can use the jquery validation message display the error code. If you want to do this, then in jquery.unobtrusive.valiation.js file

    1. Add code to duplicate the functionality of onError method in the file.
    2. Add code to interate through the error list calling your onError method to display the messages. Be careful here in that information is stored in the .data attribute of the Error Message span.
    3. You may need to write code to clear all of these errors upon submitting the form.

    This is a fairly long procedure. But the code is easily modularized into callable routines. We are currently using this in our production code and in practice, it becomes part of our framework code.

    Hope this helps.

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

Sidebar

Related Questions

I have setup the following header file to create a Stack which uses an
I have setup a simple test project for the EF 4.1 RC, using Code-First
I have setup addressbook contact's images using a code, it works well and the
I have setup a test database and console app to confirm the following: Given
I have setup the JDBC connection pooling and its showing the following error when
I have setup some automatic form submission code. Basically when a form is submitted
i have setup svn server using svnserve.exe and TortoiseSvn on my pc. svnserve.conf is
I have setup tab bar controller using interface builder, and each tab bar item
I have setup globalization on my web page and have this piece of code
I have setup the following in my urls.py: (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}) and my

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.