@Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 stringhttp://forums.asp.net/t/1800556.aspx/1?+Html+HiddenFor+for+timestamp+is+raising+an+error+The+input+is+not+a+valid+Base+64+stringMon, 07 May 2012 01:09:08 -040018005564967342http://forums.asp.net/p/1800556/4967342.aspx/1?+Html+HiddenFor+for+timestamp+is+raising+an+error+The+input+is+not+a+valid+Base+64+string@Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string <p>I have added a <strong>@Html.HiddenFor(model =&gt; model.timestamp)</strong> to my asp.net mvc view. but after submitting the view i am recieving the following error <br> <br> &nbsp;</p> <pre class="prettyprint">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.</pre> <p><br /><br />&nbsp; <br /><strong>so what might be the problem ?,</strong>, baring in mind that i have followed the same approach of adding <strong>@Html.HiddenFor(model =&gt; model.timestamp)</strong> to my other views that represents other models and they worked fine.<br />the whole view which is causing the error looks as follow:-<br /><br />&nbsp;&nbsp;&nbsp;</p> <pre class="prettyprint">@model Medical.Models.Patient @{ ViewBag.Title = "Edit"; } &lt;h2&gt;Edit&lt;/h2&gt; @section scripts{ &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt;} @using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;Patient&lt;/legend&gt; @Html.HiddenFor(model =&gt; model.PatientID) @Html.HiddenFor(model =&gt; model.timestamp) &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.FirstName) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.FirstName) @Html.ValidationMessageFor(model =&gt; model.FirstName) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.FatherName) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.FatherName) @Html.ValidationMessageFor(model =&gt; model.FatherName) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.ThirdName) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.ThirdName) @Html.ValidationMessageFor(model =&gt; model.ThirdName) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.FamilyName) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.FamilyName) @Html.ValidationMessageFor(model =&gt; model.FamilyName) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.DateOfBirth) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.DateOfBirth) @Html.ValidationMessageFor(model =&gt; model.DateOfBirth) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.NationalityID, "Country") &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.DropDownList("NationalityID", String.Empty) @Html.ValidationMessageFor(model =&gt; model.NationalityID) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.GenderID, "Gender") &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.DropDownList("GenderID", String.Empty) @Html.ValidationMessageFor(model =&gt; model.GenderID) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Weight) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Weight) @Html.ValidationMessageFor(model =&gt; model.Weight) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Height) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Height) @Html.ValidationMessageFor(model =&gt; model.Height) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.RegisterDate) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.TextBoxFor(model =&gt; model.RegisterDate , new { value = "FL", disabled = "disabled" }) @Html.ValidationMessageFor(model =&gt; model.RegisterDate) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Telephone) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Telephone) @Html.ValidationMessageFor(model =&gt; model.Telephone) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Email) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Email) @Html.ValidationMessageFor(model =&gt; model.Email) &lt;/div&gt; @Html.HiddenFor(model =&gt; model.timestamp) &lt;p&gt; @Html.HiddenFor(model =&gt; model.PatientID) @Html.HiddenFor(model =&gt; model.RegisterDate) &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; } &lt;div&gt; @Html.ActionLink("Back to List", "Index") &lt;/div&gt;</pre> <p><br /><br /><br /><br />And the&nbsp; model partial class:-<br /><br />&nbsp;&nbsp;</p> <pre class="prettyprint">namespace Medical.Models { [MetadataType(typeof(Patient_Validation))] [Bind(Exclude = "Country,Gender,Visits")] public partial class Patient {}} </pre> <p><br /><br />and the model validation:-<br /><br />&nbsp;&nbsp;&nbsp;</p> <pre class="prettyprint">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; } </pre> <p><br> <br> </p> 2012-05-06T01:47:58-04:004967381http://forums.asp.net/p/1800556/4967381.aspx/1?Re+Html+HiddenFor+for+timestamp+is+raising+an+error+The+input+is+not+a+valid+Base+64+stringRe: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string <p>You can use <code class="plain">@Html.Serialize</code> for byte arrays.</p> <p>Check out this link on the HTML.Serialize helper:</p> <p><a title="http://weblogs.asp.net/imranbaloch/archive/2011/07/26/using-the-features-of-asp-net-mvc-3-futures.aspx" href="http://weblogs.asp.net/imranbaloch/archive/2011/07/26/using-the-features-of-asp-net-mvc-3-futures.aspx">http://weblogs.asp.net/imranbaloch/archive/2011/07/26/using-the-features-of-asp-net-mvc-3-futures.aspx</a></p> 2012-05-06T03:32:22-04:004967762http://forums.asp.net/p/1800556/4967762.aspx/1?Re+Html+HiddenFor+for+timestamp+is+raising+an+error+The+input+is+not+a+valid+Base+64+stringRe: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string <p><span class="comment-copy">but why did the byte[] time stamp worked well on another view that represents other models</span>.</p> <p></p> 2012-05-06T16:01:44-04:004967770http://forums.asp.net/p/1800556/4967770.aspx/1?Re+Html+HiddenFor+for+timestamp+is+raising+an+error+The+input+is+not+a+valid+Base+64+stringRe: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string <p>It's the specific byte[] stamp causing the problem.&nbsp; Take that exact timestamp and use it in your other models and it will break them as well.</p> 2012-05-06T16:18:36-04:004967840http://forums.asp.net/p/1800556/4967840.aspx/1?Re+Html+HiddenFor+for+timestamp+is+raising+an+error+The+input+is+not+a+valid+Base+64+stringRe: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string <p>Yes&nbsp;<strong>the @Html.HiddenFor(model =&gt; model.timestamp)</strong> is what causing the problem ,, since if i remove it from the view the problme will be solved. But what is strange is that i have defined the same</p> <pre class="prettyprint">[Timestamp] public Byte[] timestamp { get; set; }</pre> <p><br> on another model and <strong>@Html.HiddenFor(model =&gt; model.timestamp)</strong> on the view and it worked fine ,, but on this specific view the error occurs?.</p> <p>BR</p> <p></p> 2012-05-06T18:24:28-04:004968014http://forums.asp.net/p/1800556/4968014.aspx/1?Re+Html+HiddenFor+for+timestamp+is+raising+an+error+The+input+is+not+a+valid+Base+64+stringRe: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string <p>Right Johnjohn.&nbsp; I think it's that specific instance of the byte[] timestamp data that is the problem, not the model.&nbsp; I'm assuming if you copied that specific data in the database to another row that would show up in the other models they would break just the same.&nbsp; So I don't think there is anything specific about the page that is breaking.&nbsp; I just think that some byte[]'s have chars that can't be converted to a Base-64 string.</p> 2012-05-07T00:59:32-04:004968017http://forums.asp.net/p/1800556/4968017.aspx/1?Re+Html+HiddenFor+for+timestamp+is+raising+an+error+The+input+is+not+a+valid+Base+64+stringRe: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string <p>Thanks for the reply; So do u suggest something like droping the timestamp column from the database and then re-create it !!!</p> <p>BR</p> 2012-05-07T01:07:15-04:004968020http://forums.asp.net/p/1800556/4968020.aspx/1?Re+Html+HiddenFor+for+timestamp+is+raising+an+error+The+input+is+not+a+valid+Base+64+stringRe: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string <p>I was just saying you could switch around some data if this is a test database to confirm if this is just a problem with @Html.HiddenFor not being able to convert some byte[]'s.&nbsp; I don't know for sure, but I'm assuming that's the case and your test could help confirm it.</p> <p>You could also just use the <code class="plain">@Html.Serialize</code> helper instead.</p> 2012-05-07T01:09:08-04:00