我有两种看法。在view1中,我很少有用于输入基本详细信息的文本框。客户输入基本详细信息并单击添加更多详细信息后,我需要将在view1中输入的详细信息传递给view2文本框。我尝试像下面这样传递,但是唯一的电子邮件显示在view2的文本框中,而不显示其他2个值。我可以看到所有3个值都传递给URL中的下一个视图,但是我无法在其各自的文本框中显示所有值。任何建议,请。
查看1:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
function myFunction() {
var email = document.getElementById('Email').value;
var firstname = document.getElementById('FirstName').value;
var lastname = document.getElementById('LastName').value;
var queryString = "?email=" + email + "&firstname=" + firstname + "&lastname=" + lastname;
window.location.href = "Home/View2" + queryString;
}
</script>
@using (Html.BeginForm("View1", "Application", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="col aligncenter">
<div class="form-row topMargin">
<div class="col-md-6 form-group">
@Html.TextBoxFor(model => model.Email)
</div>
<div class="col-md-4 form-group">
@Html.TextBoxFor(model => model.FirsttName)
</div>
<div class="col-md-2 form-group">
@Html.TextBoxFor(model => model.LastName)
</div>
</div>
<div class="form-row">
<div class="col-md-9 form-group text-right">
<button class="btn" type="button" id="add" name="add" value="add" onclick="myFunction();">Add</button>
</div>
<div class="col-md-3 form-group text-right">
<button class="btn" type="submit" name=new" value="new">view old</button>
</div>
</div>
</div>
}
查看2:
window.onload = function () {
var url = document.location.href,
params = url.split('?')[1].split('&'),
data = {}, tmp;
for (var i = 0, l = params.length; i < l; i++) {
tmp = params[i].split('=');
data[tmp[0]] = tmp[1];
}
document.getElementById("Email").value = data.email;
document.getElementById("FirstName").value = data.firstname;
document.getElementById("LastName").value = data.lastname;
}
@using (Html.BeginForm("View2", "Application", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="col aligncenter">
<div class="form-row topMargin">
<div class="col-md-6 form-group">
@Html.TextBoxFor(model => model.Email)
</div>
<div class="col-md-4 form-group">
@Html.TextBoxFor(model => model.FirsttName)
</div>
<div class="col-md-2 form-group">
@Html.TextBoxFor(model => model.LastName)
</div>
<div class="col-md-2 form-group">
@Html.TextBoxFor(model => model.address)
</div>
<div class="col-md-2 form-group">
@Html.TextBoxFor(model => model.state)
</div>
<div class="col-md-2 form-group">
@Html.TextBoxFor(model => model.zip)
</div>
</div>
<div class="form-row">
<div class="col-md-9 form-group text-right">
<button class="btn" type="submit" value="osubmit">submit</button>
</div>
</div>
</div>
}
答案 0 :(得分:0)
在form1的按钮单击事件中 txtbox.text = form2.txtbox.text
在form2的按钮单击事件中 txtbox.text = form3.txtbox.text