Summary
I am posting an object array to my asp.net-mvc backend and I generate the "Key" based on some user input and i just realized that it doesn't work if the user enters a carriage return.
Details:
So I have a form and one of my elements is an array of objects (called Deliverables)
public class FormPost
{
public int Id {get;set;}
public string ProjectName {get;set;}
public List<Deliverable> Deliverables {get;set;}
}
public class Deliverable
{
public int Id {get;set;}
public string Name {get;set;}
public DateTime MilestoneDate {get;set;}
}
I have read Phil Haack's blog post around how to do correct model binding for non sequencial object arrays here.
I am simplifying my question but i am basically using textboxes and the model binding recommendation by using something like this
<input type="text" name="Deliverables.Index" value="First">
<input type="text" name="Deliverables[First].Id" value="100">
<input type="text" name="Deliverables[First].Name" value="Name">
<input type="text" name="Deliverables[First].MilestoneDate " value="1-Jan-2104">
<input type="text" name="Deliverables.Index" value="Second">
<input type="text" name="Deliverables[Second].Id" value="88">
<input type="text" name="Deliverables[Second].Name" value="Second Name">
<input type="text" name="Deliverables[Second].MilestoneDate " value="31-Jan-2104">
So in this case I am going to have 2 entries in the Deliverables array given the textboxes above
My question is focused on what are valid values for the Index. In the case above I am using "First" and "Second" which work fine but if i have a carriage return in that string the item fails to post.
My question is "can I really use anything here?" I guess I can strip out the carriage returns on the javascript side but started thinking if there were other characters that would also fail to post.