Reputation: 89
how to implement Create action on Order and Order Details on single Create View?
http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/ is there any other simpler way to do this? MVC 3 style or in Razor View? thanks so much
Upvotes: 2
Views: 1401
Reputation: 16184
Using Razor as your view engine will not make the process simpler, just more readable. And even using ASP.NET MVC 3 you'll have to pretty much end up following the Editing a variable length list post that you mention.
Of course, you can add a new row of fields dynamically completely in jQuery, without having to create an action method for it. Something like:
<div id="fields">
<span class="row">
<input type="text" />
<input type="text" />
</span>
</div>
<a id="add" href="#">Add another</a>
<script type="text/javascript">
$(document).ready(function() {
$("#add").click(function() {
AddTextBox();
});
});
function AddTextBox() {
// clone the last span
var newRow = $("#fields .row:last").clone();
//clear any value the fields might have
$("input", newRow).val("");
//append it to the container div
$("#fields").append(newRow);
}
</script>
Still, the solution in the blog post encapsulates a new row of fields in a partial view which is rather clean.
Upvotes: 2