[英]Passing value from textbox to partial view without model MVC4
I have a view and inside that a partialview. 我有一个视图,里面有一个局部视图。 When I submit my form the action ShowDetail works perfectly and shows in a table like it should. 当我提交表单时,ShowDetail动作可以完美运行,并在应该显示的表格中显示。 There's just one thing, I want to first row to be empty except for one cell (the one with id="startvalue"). 只有一件事,我希望第一行为空,除了一个单元格(id =“ startvalue”的单元格)。 If i just type in some value inside the td-tag it works fine. 如果我只是在td标签中输入一些值,则效果很好。 But I want the value from @Html.TextBox("PresentValue"). 但是我想要来自@ Html.TextBox(“ PresentValue”)的值。
I have tried with some JQUERY but it didn't work and it kind a blocked my other JS-functions (don't know why).. 我尝试了一些JQUERY,但是它不起作用,并且它阻塞了我的其他JS函数(不知道为什么)。
So my question is if I possible can take the value from @Html.TextBox("PresentValue") and send it into on submitting a form? 所以我的问题是,如果可以的话,可以从@ Html.TextBox(“ PresentValue”)获取值并将其发送到提交表单时?
The jQuery I tried: 我尝试过的jQuery:
$(document).on('click', '#test', function()
{
var startValue = $("#PresentValue");
$("#startvalue").Append(startValue);
}
My Controller: 我的控制器:
public ActionResult ShowDetail(FormCollection form)
{
List<Calculation> cList = new List<Calculation>();
Calculation calc = new Calculation();
calc.Date = Convert.ToDateTime(form["startdate"]);
calc.InvoiceAmount = 2000;
calc.InterestRate = Convert.ToDouble(form["InterestRate"]);
calc.InterestAmount = (Convert.ToDouble(form["PresentValue"]) * Convert.ToDouble(form["InterestRate"]) / 360 * 30);
calc.Amortization = (2000 - (Convert.ToDouble(form["PresentValue"]) * Convert.ToDouble(form["InterestRate"]) / 360 * 30));
calc.PresentValue = Convert.ToDouble(form["PresentValue"]) - calc.Amortization;
cList.Add(calc);
for (int i = 0; i < Convert.ToInt32(form["PaymentPeriods"]); i++)
{
Calculation calcBefore = cList.Last();
calc = new Calculation();
calc.Date = calcBefore.Date.AddMonths(1);
calc.InvoiceAmount = 2000;
calc.InterestRate = Convert.ToDouble(form["InterestRate"]);
calc.InterestAmount = (calcBefore.PresentValue * Convert.ToDouble(form["InterestRate"]) / 360 * 30);
calc.Amortization = (calc.InvoiceAmount - (calcBefore.PresentValue * calc.InterestRate / 360 * 30));
calc.PresentValue = calcBefore.PresentValue - calc.Amortization;
cList.Add(calc);
}
return PartialView("ShowDetail", cList);
}
My PartialView: 我的PartialView:
<tr>
<td align="center">
</td>
<td align="center">
</td>
<td align="center">
</td>
<td align="center">
</td>
<td align="center">
</td>
<td align="center" id="startValue">
//Here do I want the value from @Html.Textbox("PresentValue")
</td>
</tr>
@foreach (var item in Model)
{
<tr>
<td align="center">
@Html.DisplayFor(modelItem => item.Date)
</td>
<td align="center">
@Html.DisplayFor(modelItem => item.InvoiceAmount)
</td>
<td align="center">
@Html.DisplayFor(modelItem => item.InterestRate)
</td>
<td align="center">
@Html.DisplayFor(modelItem => item.InterestAmount)
</td>
<td align="center">
@Html.DisplayFor(modelItem => item.Amortization)
</td>
<td align="center">
@Html.DisplayFor(modelItem => item.PresentValue)
</td>
</tr>
}
In my View (inside a BeginForm): 在我看来(在BeginForm内):
@Html.TextBox("PresentValue")
Try to change your jquery snippet to something like this: 尝试将您的jquery代码段更改为以下形式:
$(document).on('click', '#test', function()
{
var startValue = $("#PresentValue").val();
$("#startvalue").text(startValue);
}
Try 尝试
$(document).ready(function()
{
var startValue = $("#PresentValue").val();
$("#startvalue").text(startValue);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.