asp.net - Display text when button clicked -


creating first asp.net mvc knockout mvc.

i've added model setting 3 dates. controller assigns 3 dates. displayed on screen using view:

<p>first date: @ko.html.textbox(m => m.firstdate)</p> <p>second date: @ko.html.textbox(m => m.seconddate)</p> <p>third date: @ko.html.textbox(m => m.thirddate)</p>  @ko.apply(model) 

the @ko.apply(model) being main part displays 3 dates. trying show 3 dates when button clicked, iv put code inside form , used button:

<form id="displaydates" method="post" > <p>first date: @ko.html.textbox(m => m.firstdate)</p> <p>second date: @ko.html.textbox(m => m.seconddate)</p> <p>third date: @ko.html.textbox(m => m.thirddate)</p>  <input id="btn" type="button" value="click" @ko.apply(model) /> </form> 

problem being no longer displays dates in text box, display them beside button. recpa: each date appear inside text box when button clicked (instead of alongside button when page loads - happens atm).

any ideas? enter image description here

update tried add button, dates dont display @ all, when button clicked.

view:

@using perpetuumsoft.knockout @model knockoutmvc3dates.models.datesmodel        @{   var ko = html.createknockoutcontext(); }  <p>first date: @ko.html.textbox(m => m.firstdate)</p> <p>second date: @ko.html.textbox(m => m.seconddate)</p> <p>third date: @ko.html.textbox(m => m.thirddate)</p>  @ko.html.button("display","index","dates",null,null) 

dates controller:

   public actionresult index()         {             return view                 (   new datesmodel                     {                         firstdate = datetime.now,                          seconddate = datetime.now.addyears(1).addmonths(1),                         thirddate = datetime.now.addyears(2).addmonths(2)                     }                 );          } 

model:

  public class datesmodel {     public datetime firstdate { get; set; }     public datetime seconddate { get; set; }     public datetime thirddate { get; set; } } 

any or ideas welcome??

maybe want this?

<input id="btn" type="button" value="click" onclick="@(ko.apply(model))" /> 

i not familiar knockout js appears return value of ko.apply(model) bunch of js populate fields. if want run on click of button, you'll want above. right now, you're writing out load of js input tag, breaking.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -