jquery - Persist ID throughout ASP.NET MVC Views -


basically have image upload controller, inserting in pages follows :-

    <div id='imagelist'>     <h2>upload image(s)</h2>     @{         if (model != null)         {             html.renderpartial("~/views/file/imageupload.cshtml", new mvccommons.viewmodels.imagemodel(model.project.projectid));         }           else         {             html.renderpartial("~/views/file/imageupload.cshtml", new mvccommons.viewmodels.imagemodel(0));         }     } </div> 

so passing id imageupload, in case projectid, can include in insert.

now piece of code populating imagemodel(id), in case projectid :-

    public imagemodel(int projectid)     {         if (projectid > 0)         {             projectid = projectid;             var imagelist = unitofwork.imagerepository.get(d => d.itemid == projectid && d.pageid == 2);             this.addrange(imagelist);         }     } 

and in turn leads imageuploadview.cshtml :-

<table> @if (model != null) {   foreach (var item in model)   {      <tr>         <td>           <img src= "@url.content("/uploads/" + item.filename)" />         </td>         <td>           @html.displayfor(modelitem => item.description)         </td>     </tr>      } } </table>  @using (html.beginform("save", "file", new { projectid = model.projectid },         formmethod.post, new { enctype = "multipart/form-data" }))  {     <input type="file" name="file" />     <input type="submit" value="submit" /> <br />     <input type="text" name="description" />  } 

so far good, problem first time

new { projectid = model.projectid } 

is correctly populated projectid, however, when upload image, projectid lost, , becomes zero. there way can persist projectid second time?

thansk , time.

********* update ************************* after upload, action follows inside filecontroller :-

        public actionresult save(int projectid)     {         foreach (string name in request.files)         {             var file = request.files[name];              string filename = system.io.path.getfilename(file.filename);             image image = new image(filename, request["description"]);              imagemodel model = new imagemodel();             model.populate();             model.add(image, file);         }         return redirecttoaction("imageupload");     } 

you can pass projectid route value redirecttoaction. should change imageupload action accept projectid.

public actionresult save(int projectid) {   ....   return redirecttoaction("imageupload", new { projectid = projectid }); }  public actionresult imageupload(int projectid) {    var model = .. model db based on projectid    return view("view name", model);    } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -