1

I have a simple form with 4 input on it.

  • 2 text input
  • 2 check boxes

My current view model posted to server is like the following:

public class MyViewModel {
    public string FirstText { get; set; }
    public string SecondText { get; set; }
    public bool FirstBool { get; set; }
    public bool SecondBool { get; set; }
}

This works good. I have now the requirement that when the SecondBool value is true the UI should also upload a file to the server. Then I have modified the view model to add

public HttpPostedFileBase UploadedFile { get; set; }

and modified the form to having an attribute enctype="multipart/form-data"

I would like to use, as I am using bootstrap as the base UI framework the jQuery File Upload plugin but did not get through on how to post and upload the file at the same time. I know it should be very easy to do it.

Any hint?

1 Answer 1

2

You will need to add the HttpPostedFileBase UploadedFile to your post action in your controller. You cannot pass via the model.

E.g.

[HttpPost]
public ActionResult MyAction(MyModel model, HttpPostedFileBase UploadedFile)
{
    //..... Do stuff here
}
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your answer. Any suggestion on the client plugin configuration please?
There is a good sample here: powerdotnetcore.com/asp-net-mvc/…
@Lorenzo If you take a look at the link provided by nik0lias (powerdotnetcore.com/asp-net-mvc/…) you will find a great sample to add jQuery file upload to MVC project.
@nik0lias: Yes I have seen that link before. Unfortunately that link upload the file as soon as the file is selected in the file input. I am getting stuck with uloading when the form is submitted
The example in that link is triggered by button click, could you post what you have so far? In your view?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.