c# - MVC Model and Controller for Uploaded files -


My fellow community, I have to make sure that I want to develop it correctly I am ASP.NET MVC 5 application I am working on, and while developing the application, I am studying the architecture of MVC and also to ensure that I really understand the architecture of MVC.

I currently see one (see below) which will allow multiple files to be uploaded at the click of a submit button.

  & lt; H2 & gt; Upload multiple documents & lt; / H2 & gt; Using a single @ (HTML) beniform ("upload", "home", a form.mast.prost, a new one (an encryptpie = "multipart / form-data" one)) a  M.file, a new, one type of file = "id" = "logofile" a))) one each one one one one one one  & lt; Label & gt; Privacy pdf: & lt; / Labels & gt; A @ (HTML Testbox file (model = & gt; a model.file, a new one (a type of file = "file", an id = "privacy file"}}) a one to one one one one one a & Lt; label & gt; Payment Terms PDF: & lt; / label & gt; a @ (Html.TextBoxFor (model = & gt; a model file, a new one (a type = "file", an id = " PaymentTerms "One})) One A One One One One One One Labels & gt; Faq File: & lt; / Labels & gt; A @ (HTML Text BoxFolder (Model => A Model. , A new (one type = "f IL ", an id =" onefacfile "))) a one-by-one-one-one-a-   

so it will call the controller (note I need to add a foreach loop to handle multiple files), more on that -

  [http post] is a public action Action Upload (UploadFileModel FileModel) A Destined String Path = A @ "C: \ _Temporary \"; If A (ModelState .Is.I. Iaidiaidi) A A A A A A A A A A A A A A A A Vara resulta = a Path.GetFileName (fileModel.File.FileName); One if (resultÂ! = A null) a one to one one one one one one one one one one one one one one one  ° Vara sections = one result.Split ('\\'); One a one one one one one one one one one one one one one one a vara fileName = one sections sections.Length -a 1; One a one one one one one one one one one one one one one a fileModel.File.SaveAs (Patha + a file name); One return one redirection ("index") one; A   

which then calls the model -

  PublicFileFileModel / //: An IEnumerable one (a) [FileSize (10240)] [ FileTypes ("JPG, JPEG, PNG, PDF")] A public one HttpPostedFileBase file (get one); One set; Added after one / // comments - I will add it here ????????? Public IEnumerable & lt; UploadFileModel & gt; Upload file modals {receive; Set; }   

My idea is that the controller code should be taken from the model to what I am reading and books.

Question 1 - Should the code be transferred to the model in the controller? Since I am researching business logic, hence the model should handle. Question 2 - Since this collection will be (I'm not strong on the collection, but I am trying to become a master).
a) Do I add another category for the collection called Upload File Models which is strictly for archiving or am I uploading the upload file model to upload and then handling the archive and if so how?

Thank you.

  Upload Public Actions (IEnumerable & lt; UploadFileModel & gt; File Model)   

and your model class should be:

  public class UploadFileModel //: IEnumerable {[FileSize (10240)] [file type ("jpg, jpeg, png, pdf")] Public HTTP post filebase file {get; Set; }}   

And your controller now takes a collection as a side note in the form of your model class, still you do not really need it at all, you just

  can use public action resolution uploads (IEnumerable & lt; HttpPostedFileBase & gt; File Model)   

and make your business logic in a controller repository model . I do not recommend doing this, because if you want to make changes to your controller, it makes it more difficult, but it is worth noting

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -