【发布时间】:2020-06-30 16:24:35
【问题描述】:
我对理解 Razor 页面还很陌生,并且在发布表单后检索模型数据时遇到问题。它能够在页面加载时检索数据,但是一旦我发布表单,模型就为空。这是一个大公司项目的一部分,所以我很难发布所有数据,但这是代码的相关sn-p:
@inherits ViewPage<ViewModels.User.SignUp.VerifyActivationCodeModel>
@using (Ajax.BeginForm(nameof(SignUpController.VerifyActivationCode),
SignUpController.ControllerName, null, new AjaxOptions
{
HttpMethod = "POST",
OnSuccess = "VerifyActivationCodePage.OnSuccess",
OnFailure = "ErrorHelper.HandleError"
}, new { id = "verifyActivationCodeForm", autocomplete = "off" }))
{
@Html.AntiForgeryToken()
<div class="">
<div class="">
<h3 class="">
@Html.Raw(Model.Title)
</h3>
</div>
</div>
<div class="">
<div class="">
<fieldset class="form-row">
@Html.TextBoxSensitiveFor(m => m.ActivationCode,
new
{
placeholder = string.Format(ResourceManager.GetResource("VerifyToken"), Model.Token),
@class = "in-text",
maxlength = "100"
})
// rest of form ...
当我发布此表单时,我尝试填充为占位符的 Model.Token 为“Null”,而在发布之前它已成功从资源中填充。
有人可以帮忙吗?谢谢
【问题讨论】:
-
在表单中添加@Html.HiddenFor(m => m.Token),看看是否有帮助。
-
成功了,非常感谢@KevinAmorim!
-
不错!将其发布为答案:)
标签: c# asp.net-mvc razor