javascript - Append Hidden input fields and bind them to the Model -



javascript - Append Hidden input fields and bind them to the Model -

i'm usinge 3rd party file uploader(backload)to upload images & javascript uploaded image names.i want bind list of image names mvc model. requirement create hidden inputs dynamically when submit form. know , have utilize sequential binding here loop. can help me how utilize proper syntax accomplish this. should similar this

class="lang-c# prettyprint-override">for (int i= 0; i< noofimages; i++) { <input type="hidden" name="model.images[i].name" value=file.name /> }

(please note don't want ajax solution , please show me code utilize in razor view or if there improve solution please allow me know).thanks.

public class itemmodel { public int id { get; set; } public string name { get; set; } public virtual icollection<imagemodel> images { get; set; } } public class imagemodel { public int id { get; set; } public string name { get; set; } public virtual itemmodel items { get; set; } }

i utilize next javascript code values of uploaded file name , create hidden inputs when click submit button of #itemcreate form.

$('#imageuplodedtable input[name="imagename"]').each(function () { $('#itemcreateform').append('<input name="imagename" value="' + this.value + '"/>');

i'm adding below part question. missed single quotes , 2 plus signs ['+i+'] it's working fine.

$('#imageuplodedtable input[name="imagename"]').each(function () { (int i= 0; i< noofimages; i++) { <input type="hidden" name="images[+'i'+].name" value="' + this.value + '" /> }

i can't utilize .each() loop here.can suggest way image names in uploded table?

you've done right in loop @ top, 1 time javascript portion, you're bungling names. maintain names of input in same style first loop , you'll fine, i.e. images[n].name n index of item in collection.

javascript jquery asp.net-mvc razor

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -