1

@Html.HiddenFor(model => model.timestamp)asp.net mvc ビューに を追加しました。しかし、ビューを送信した後、次のエラーが表示されます

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

1 に答える 1

0

バイト配列には @Html.Serialize を使用できます。

HTML.Serialize ヘルパーの次のリンクを確認してください。

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

于 2012-05-06T03:33:20.020 に答える