Tuesday, July 31, 2012

Dynamically Generate Form with jQuery and ASP.NET MVC


http://derans.blogspot.ca/2012/07/dynamically-generate-form-with-jquery.html

function GenerateAndSubmitForm(action) {
    var body = $('body');
    var form = $("<form method='post' action=" + action + "/>");
    @foreach(var param in Model.ToParameterList())
    {
        @Html.Raw("form.append($(\"<input type='hidden' name='" + @param.Key + "' value='" + @param.Value + "' />\"));")
    }
    body.append(form);
    form.submit();
}