【问题标题】:@Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string@Html.HiddenFor 的时间戳引发错误输入不是有效的 Base-64 字符串
【发布时间】:2012-05-05 19:19:55
【问题描述】:

我在我的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>

:::--UPDATED--:::

这是模型部分类:-

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; }

【问题讨论】:

  • 能否给我们看看型号
  • 我用模型类更新了我的原始帖子。谢谢

标签: asp.net asp.net-mvc-3 hidden-field


【解决方案1】:

您可以将@Html.Serialize 用于字节数组。

在 HTML.Serialize 帮助器上查看此链接:

http://weblogs.asp.net/imranbaloch/archive/2011/07/26/using-the-features-of-asp-net-mvc-3-futures.aspx

【讨论】:

  • 但是为什么 byte[] 时间戳在代表其他模型的另一个视图上运行良好
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-13
  • 1970-01-01
  • 2012-09-22
相关资源
最近更新 更多