我正在尝试编写银行申请。在事务页面中,我想从用户帐户数据库(User.Identity.GetUserId())中获取CheckingAccountId的值。但是,如何将User.Identity.GetUserId()的值分配给CheckingAccountId。这是相关的Razor View页面代码:
using (Html.BeginForm("Deposit", "Transaction", FormMethod.Post, new {
@class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken();
<h4>Deposit Section</h4>
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.Id, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.Id, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.TransactionAmount, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.TransactionAmount, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.CheckingAccountId, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@{
var userName = User.Identity.GetUserName();
}
@*THIS IS THE BEST I COULD DO. I NEED HELP HERE*@
@*@m.CheckingAccountId = userName*@
@Html.DisplayName(userName)**
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Deposit" />
</div>
</div>
更新: 我刚刚发现,可以通过在编写用于将事务推送到数据库的SQL查询时在ConnectionString中添加相同的内容来实现此目的。解决方案如下所示:
INSERT INTO table ( checkingaccountid, model_data ) VALUES ( $id, $data );
但是我仍然想知道在与其他数据一起提交时是否可以从表单发送此ID。