razor - Asp.Net MVC validation & knockout foreach -


i have mvc 4 validation & knockout issue.

i tried solution :

translate knockout razor keep it's validation working

but have same problem listed in comment of valid answer => validation works first element.

after several searches, found article on model binding list :

http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/

i wondering how merge 2 solutions.

sample validation working first element :

dim dummy viewmodels.objectviewmodel = model.myobjects.firstordefault  @<tbody data-bind='foreach: myobjects'>    <td>                         @html.textboxfor(function(model) dummy.label, new {.data_bind = "value: label"})    </td> </tbody> 

sample validation working, without knockout foreach, can't add items dynamically

<tbody>      @code          dim integer = 0          each object in model.myobjects             @<tr>                <td>                      @html.textboxfor(function(m) model.myobjects(i).label)                                  </td>                    </tr>                                     i+= 1          next      end code </tbody> 

maybe knockout variable : $index() ?

in past i’ve tried force combining razor , knockout. more opt go 1 way or other. if i’m going render on client side, i’ll go ahead , define in terms of html directly instead of going through razor.

probably best bet here define html elements directly. if need have validation on place, make sure of 2 things:

  1. set corresponding jquery validate attributes (e.g. data-val-true) form validates on client side.
  2. if you’re submitting data asp.net mvc controller make sure elements have same name/id needed controller binding takes place on controller method parameters.

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -