I have added a @Html.HiddenFor(model => model.timestamp) to my asp.net mvc view. but after submitting the view i am recieving the following error
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.
so what might be the problem ?,, baring in mind that i have followed the same approach of adding @Html.HiddenFor(model => model.timestamp) to my other views that represents other models and they worked fine. the whole view which is causing the error looks as follow:-
Yes the @Html.HiddenFor(model => model.timestamp) 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
[Timestamp]
public Byte[] timestamp { get; set; }
on another model and @Html.HiddenFor(model => model.timestamp) on the view and it worked fine ,, but on this specific view the error occurs?.
Right Johnjohn. I think it's that specific instance of the byte[] timestamp data that is the problem, not the model. 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. So I don't think there is anything specific about the page that is breaking. I just think that some byte[]'s have chars that can't be converted to a Base-64 string.
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. I don't know for sure, but I'm assuming that's the case and your test could
help confirm it.
You could also just use the @Html.Serialize helper instead.
johnjohn1231...
Participant
922 Points
871 Posts
@Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string
May 06, 2012 01:47 AM|LINK
I have added a @Html.HiddenFor(model => model.timestamp) to my asp.net mvc view. but after submitting the view i am recieving the following error
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.so what might be the problem ?,, baring in mind that i have followed the same approach of adding @Html.HiddenFor(model => model.timestamp) to my other views that represents other models and they worked fine.
the whole view which is causing the error looks as follow:-
@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>And the model partial class:-
namespace Medical.Models { [MetadataType(typeof(Patient_Validation))] [Bind(Exclude = "Country,Gender,Visits")] public partial class Patient {}}and the model validation:-
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; }hoopslife
Contributor
2477 Points
483 Posts
Re: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string
May 06, 2012 03:32 AM|LINK
You can use
@Html.Serializefor byte arrays.Check out this link on the HTML.Serialize helper:
http://weblogs.asp.net/imranbaloch/archive/2011/07/26/using-the-features-of-asp-net-mvc-3-futures.aspx
Blog
johnjohn1231...
Participant
922 Points
871 Posts
Re: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string
May 06, 2012 04:01 PM|LINK
but why did the byte[] time stamp worked well on another view that represents other models.
hoopslife
Contributor
2477 Points
483 Posts
Re: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string
May 06, 2012 04:18 PM|LINK
It's the specific byte[] stamp causing the problem. Take that exact timestamp and use it in your other models and it will break them as well.
Blog
johnjohn1231...
Participant
922 Points
871 Posts
Re: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string
May 06, 2012 06:24 PM|LINK
Yes the @Html.HiddenFor(model => model.timestamp) 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
[Timestamp] public Byte[] timestamp { get; set; }on another model and @Html.HiddenFor(model => model.timestamp) on the view and it worked fine ,, but on this specific view the error occurs?.
BR
hoopslife
Contributor
2477 Points
483 Posts
Re: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string
May 07, 2012 12:59 AM|LINK
Right Johnjohn. I think it's that specific instance of the byte[] timestamp data that is the problem, not the model. 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. So I don't think there is anything specific about the page that is breaking. I just think that some byte[]'s have chars that can't be converted to a Base-64 string.
Blog
johnjohn1231...
Participant
922 Points
871 Posts
Re: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string
May 07, 2012 01:07 AM|LINK
Thanks for the reply; So do u suggest something like droping the timestamp column from the database and then re-create it !!!
BR
hoopslife
Contributor
2477 Points
483 Posts
Re: @Html.HiddenFor for timestamp is raising an error The input is not a valid Base-64 string
May 07, 2012 01:09 AM|LINK
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. I don't know for sure, but I'm assuming that's the case and your test could help confirm it.
You could also just use the
@Html.Serializehelper instead.Blog