Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay text when button clicked
    text
    copied!<p>Creating my first ASP.NET MVC Knockout MVC.</p> <p>I've added a model setting 3 dates. The controller assigns 3 dates. Then they are displayed on screen using the view:</p> <pre><code>&lt;p&gt;First Date: @ko.Html.TextBox(m =&gt; m.FirstDate)&lt;/p&gt; &lt;p&gt;Second Date: @ko.Html.TextBox(m =&gt; m.SecondDate)&lt;/p&gt; &lt;p&gt;Third Date: @ko.Html.TextBox(m =&gt; m.ThirdDate)&lt;/p&gt; @ko.Apply(Model) </code></pre> <p>The @ko.Apply(Model) being the main part which displays the 3 dates. I am trying to only show the 3 dates when a button is clicked, so iv put the code inside a form and used a button:</p> <pre><code>&lt;form id="displaydates" method="post" &gt; &lt;p&gt;First Date: @ko.Html.TextBox(m =&gt; m.FirstDate)&lt;/p&gt; &lt;p&gt;Second Date: @ko.Html.TextBox(m =&gt; m.SecondDate)&lt;/p&gt; &lt;p&gt;Third Date: @ko.Html.TextBox(m =&gt; m.ThirdDate)&lt;/p&gt; &lt;input id="btn" type="button" value="click" @ko.Apply(Model) /&gt; &lt;/form&gt; </code></pre> <p>Problem being this no longer displays the dates in the text box, they display them beside the button. To recpa: I would like each date to appear inside the text box when the button is clicked (instead of alongside the button when the page loads - which is what happens atm).</p> <p>Any ideas? <img src="https://i.stack.imgur.com/qXD68.png" alt="enter image description here"></p> <p>Update Tried to add a button, but now the dates dont display at all, even when the button is clicked.</p> <p>View:</p> <pre><code>@using PerpetuumSoft.Knockout @model KnockOutMVC3Dates.Models.DatesModel @{ var ko = Html.CreateKnockoutContext(); } &lt;p&gt;First Date: @ko.Html.TextBox(m =&gt; m.FirstDate)&lt;/p&gt; &lt;p&gt;Second Date: @ko.Html.TextBox(m =&gt; m.SecondDate)&lt;/p&gt; &lt;p&gt;Third Date: @ko.Html.TextBox(m =&gt; m.ThirdDate)&lt;/p&gt; @ko.Html.Button("Display","Index","Dates",null,null) </code></pre> <p>Dates Controller:</p> <pre><code> public ActionResult Index() { return View ( new DatesModel { FirstDate = DateTime.Now, SecondDate = DateTime.Now.AddYears(1).AddMonths(1), ThirdDate = DateTime.Now.AddYears(2).AddMonths(2) } ); } </code></pre> <p>Model:</p> <pre><code> public class DatesModel { public DateTime FirstDate { get; set; } public DateTime SecondDate { get; set; } public DateTime ThirdDate { get; set; } } </code></pre> <p>Any help or ideas welcome??</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload