当单击按钮显示文本 [英] Display text when button clicked
问题描述
创建我的第一个ASP.NET MVC淘汰赛MVC。
Creating my first ASP.NET MVC Knockout MVC.
我添加了一个模型设置3日期。该控制器分配3日期。然后,他们正在使用的视图显示在屏幕上:
I've added a model setting 3 dates. The controller assigns 3 dates. Then they are displayed on screen using the 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)
的
@ ko.Apply(模型)是其中显示了3日期的主要部分。
我想只能说明当一个按钮被点击3日期,所以四把code表格内所使用的按钮:
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:
<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>
问题是这不再显示的日期在文本框中,它们显示它们的按钮旁边。要recpa:我想每个日期出现在文本框内单击该按钮时(而不是旁边的按钮时,页面加载 - 这是发生了什么大气压)
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).
任何想法?
Any ideas?
更新尝试添加一个按钮,但现在不日期显示所有,单击该按钮时也是如此。
Update Tried to add a button, but now the dates dont display at all, even when the button is clicked.
查看:
@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)
日期控制器:
public ActionResult Index()
{
return View
( new DatesModel
{
FirstDate = DateTime.Now,
SecondDate = DateTime.Now.AddYears(1).AddMonths(1),
ThirdDate = DateTime.Now.AddYears(2).AddMonths(2)
}
);
}
型号:
public class DatesModel
{
public DateTime FirstDate { get; set; }
public DateTime SecondDate { get; set; }
public DateTime ThirdDate { get; set; }
}
任何帮助或想法表示欢迎??
Any help or ideas welcome??
推荐答案
input标签可以在这里使用的一样
在onclick事件ü可以给模型的名称也
试试这个...
input tag can be used here like on the onclick event u can give the name of the model also try this...
这篇关于当单击按钮显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!