我在我的asp.net mvc视图中添加了@Html.HiddenFor(model => model.timestamp)
。但在提交视图后,我收到了以下错误
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
所以可能是什么问题,请记住,我已经按照相同的方法将@Html.HiddenFor(model => model.timestamp)
添加到代表其他模型的其他视图中,并且它们工作正常。
导致错误的整个视图如下所示: -
@model Medical.Models.Patient
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@section scripts{
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>}
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Patient</legend>
@Html.HiddenFor(model => model.PatientID)
@Html.HiddenFor(model => model.timestamp)
<div class="editor-label">
@Html.LabelFor(model => model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FirstName)
@Html.ValidationMessageFor(model => model.FirstName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.FatherName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FatherName)
@Html.ValidationMessageFor(model => model.FatherName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ThirdName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ThirdName)
@Html.ValidationMessageFor(model => model.ThirdName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.FamilyName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FamilyName)
@Html.ValidationMessageFor(model => model.FamilyName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.DateOfBirth)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DateOfBirth)
@Html.ValidationMessageFor(model => model.DateOfBirth)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.NationalityID, "Country")
</div>
<div class="editor-field">
@Html.DropDownList("NationalityID", String.Empty)
@Html.ValidationMessageFor(model => model.NationalityID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.GenderID, "Gender")
</div>
<div class="editor-field">
@Html.DropDownList("GenderID", String.Empty)
@Html.ValidationMessageFor(model => model.GenderID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Weight)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Weight)
@Html.ValidationMessageFor(model => model.Weight)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Height)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Height)
@Html.ValidationMessageFor(model => model.Height)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.RegisterDate)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.RegisterDate , new { value = "FL", disabled = "disabled" })
@Html.ValidationMessageFor(model => model.RegisterDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Telephone)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Telephone)
@Html.ValidationMessageFor(model => model.Telephone)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
@Html.HiddenFor(model => model.timestamp)
<p>
@Html.HiddenFor(model => model.PatientID)
@Html.HiddenFor(model => model.RegisterDate)
<input type="submit" value="Save" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
::: - 更新 - :::
这是模型分部类: -
namespace Medical.Models
{
[MetadataType(typeof(Patient_Validation))]
[Bind(Exclude = "Country,Gender,Visits")]
public partial class Patient
{}}
和模型验证: -
public class Patient_Validation
{
[DisplayFormat(DataFormatString = "{0:f}", ApplyFormatInEditMode = true)]
[Display(Name = "Register Date")]
public double RegisterDate { get; set; }
[Timestamp]
public Byte[] timestamp { get; set; }
//[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
[DisplayFormat(DataFormatString = "{0:f}", ApplyFormatInEditMode = true)]
[Display(Name = "Date Of Birth")]
public double DateOfBirth { get; set; }
[StringLength(50,MinimumLength=2)]
[Display(Name = "First Name")]
[MaxWords(10)]
public string FirstName { get; set; }
[StringLength(50, MinimumLength = 2)]
[Display(Name = "Father Name")]
[MaxWords(10)]
public string FatherName { get; set;}
[StringLength(50,MinimumLength=2)]
[Display(Name = "Third Name")]
[MaxWords(10)]
public string ThirdName { get; set; }
[StringLength(50,MinimumLength=2)]
[Display(Name = "Family Name")]
[MaxWords(10)]
public string FamilyName { get; set;
[Required(ErrorMessage= "Gender is Required")]
[Display(Name = "Gender")]
public int GenderID { get; set; }
[RegularExpression(@"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}",ErrorMessage="Please Insert Valid Email Address")]
public string Email { get; set; }
答案 0 :(得分:0)
您可以将@ Html.Serialize用于字节数组。
在HTML.Serialize助手上查看此链接: