-1

here was my code from view

@{ var companies = (IEnumerable<Company>)ViewData["companylist"]; }
@foreach (var item in companies)
{
    //post the form to upload actions, index2 for testing
       <form id="submitfinal" method="post" asp-action="Upload" asp-controller="report" enctype="multipart/form-data">
            <input type="hidden" name="companyid" value="@item.Id" />
            @item.Name (@item.Status)

            <input type="file" name="files" />
            <input name="submit" type="submit" value="upload final report" />

    </form>

}

Question here was how can i take the data from input tag attribute to controller? let say the @item.Id is 1234, how i get that in controller?

Dustin Kingen
  • 20,677
  • 7
  • 52
  • 92
Jessica
  • 23
  • 3
  • 14
  • In the ViewModel (or in function arguments) for the controller's method `ReportController.Upload` which handles the POST request, called when user submits the form. Can I suggest to follow an ASP.NET Core tutorial? It will introduce this _concept_ in the easy way. – Adriano Repetti Jul 27 '17 at 06:56
  • how exactly i can get the value of input tag's attribute data in controller? – Jessica Jul 27 '17 at 07:02
  • https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-controller – Adriano Repetti Jul 27 '17 at 07:15
  • @AdrianoRepetti this is not the answer i want – Jessica Jul 27 '17 at 07:20
  • [HttpPost] public async Task Upload(ICollection files, FormCollection form) {var inputForm = form["inputForm"];} let say this is how to get the form, but i am wanting the data from the value attribute – Jessica Jul 27 '17 at 07:22
  • Did you read the linked tutorial? It's exactly accepting parameters (as for files they're arguments for your function or properties in the VM built by ASP.NET MVC runtime and passed as...argument). We might write a 30 lines answer but everything is already in docs (really!). Don't try to solve _problems_ one by one before you went through the basics. – Adriano Repetti Jul 27 '17 at 07:31
  • What exactly you want? Get a particular model property value on postback or you want a value in post? – HEGDE Jul 27 '17 at 08:25

2 Answers2

0

you can use

 @Html.HiddenFor(m => m.yourPropertyname)

or using jquery ajax you can send the value to controller.

Tonmoy Saha
  • 652
  • 1
  • 5
  • 13
  • how i get that in controller? – Jessica Jul 27 '17 at 07:29
  • OP already has this in her code (just different form), she is asking for another (trivial) thing which is how to get back that value in the controller method invoked on POST. – Adriano Repetti Jul 27 '17 at 07:32
  • 1
    This is what you need i think. same question.. [link] (https://stackoverflow.com/questions/14124324/submitting-form-and-pass-data-to-controller-method-of-type-filestreamresult) – Tonmoy Saha Jul 27 '17 at 07:37
0

Maybe it's too late, but I would use asp-route-Id like:

<form id="submitfinal" method="post" asp-route-Id="@item.Id" asp-action="Upload" asp-controller="report" enctype="multipart/form-data">
Dunedan
  • 7,848
  • 6
  • 42
  • 52
Wilfredo
  • 41
  • 3