There's sometimes that you need to add another textbox or other input type for additional information. Ok, say, A Customer can have many Address. As the user completes the form and as he reach the address he can hit the plus sign to add another textbox for another address. So what I did is something like this: (don't know if it's recommended or not)
Html:
<a href="#" class="add-address">Additional Address</a>
<div class="address-container"></div>
JS:
<script>
$(function() {
var i = 0;
var addAddress = function() {
var strBuilder = '<input type="text" name="Addresses[i].Location" />';
$('.address-container').append(strBuilder);
i++;
return false;
};
$('.add-address').click(addAddress);
});
</script>
So my question is:
- It is possible to add the textbox as this
@Html.EditorFor()? - It would really be great if I can also add in the
@Html.ValidationMessageFor(), is it possible?
I'm using ASP.NET MVC 4; EF Code first approach.
Any help would be much appreciated. Thanks.
@is used to denote the start of a .NET statement in a Razor view.Htmlis a reference toHtmlHelper- this isn't available to client-side code and therefore can't be called in JavaScript.