これには簡単な答えがあると確信しています。私の無知を許してください。15 年間 ASPNET WebForms を使用してきた後、この新しい Web v2.0 の機能が私の背中を蹴っています。
WebUser
HttpPost でオブジェクトが null である理由を理解しようとしています。
だから私はこのコントローラーアクションを持っています:
[HttpGet]
public ViewResult PrivateKey()
{
var pk = new PrivateKey { WebUser = GetWebUserFromSession() };
return View(pk);
}
これは正常に機能し、私の剃刀ビューは問題なくメンバーにアクセスできますPrivateKey.WebUser
。
問題は HttpPost アクションで発生します。
[HttpPost]
public ActionResult PrivateKey(PrivateKey pkey)
{
if (string.IsNullOrEmpty(pkey.Value))
return View(pkey);
// pkey.WebUser is always null :(
// TestKeyAgainstMockCipher(pkey.Value, pkey.WebUser);
InsertSecuredMasterKeyIntoSession(pkey.Value);
return RedirectToAction("Index", "Home");
}
したがって、完全に正当であると確信している理由から、私のPrivateKey
オブジェクトは HttpPost を通過しても問題ありませんがWebUser
、オブジェクト内に含まれる参照されたプロパティPrivateKey
は常に null です。
[Serializable]
MVC がプロパティに属性を配置する必要があるのWebUser
か 、それとも HttpPost を間違って使用しているのか、それとも維持するのではなく、データを常に取得するために I/O データストアに継続的に戻って実行するという MVC で受け入れられている慣行なのかはわかりません渡されるメモリ内の標準オブジェクト指向データ構造。
それが助けになるなら、ここに私が働こうとしているビューがあります:
@model KeePassWeb.Domain.Models.PrivateKey
@{
ViewBag.Title = "PrivateKey";
Layout = "~/Views/Shared/_MasterPage.cshtml";
}
@using (Html.BeginForm())
{
<div class="privatekey">
<table style="">
<tr>
<td style="width:128px; height: 75px;"></td>
<td style="width:291px; height: 75px;"></td>
</tr>
<tr>
<td style="width:128px; height: 25px;"></td>
<td style="width:291px; height: 25px; ">
@Html.PasswordFor(x =>x.Value, new { @class = "form-control", id="txtMasterPass", style = "width:65%", placeHolder = "Password" })
<input Id="btnMasterPass" type="submit" value="Submit" class="submit" />
</td>
</tr>
</table>
</div>
<table>
<tr>
<td><img src="../Images/big_info.png" height="32px" width="32px" style="margin-right:8px;" alt="info" /></td>
<td>
@if (string.IsNullOrEmpty(@Model.WebUser.Padding)) {
@:This is your first login. Please create a private key passphrase.
}
else {
@:Please enter your private key to access your wallet.
}
</td>
</tr>
</table>
}
<script type="text/javascript">
$("#wallet").addClass("active");
</script>
要するに、httpPost
コントローラー アクションがポストバックから有効なPrivateKey
オブジェクトを受け取っているのに、オブジェクト内に含まれるPrivateKey
オブジェクトが常に null である理由がわかりません。
前もって感謝します!--オールドタイマー:)