-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?

7
  • 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. Commented Jul 27, 2017 at 6:56
  • how exactly i can get the value of input tag's attribute data in controller? Commented Jul 27, 2017 at 7:02
  • learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/… Commented Jul 27, 2017 at 7:15
  • @AdrianoRepetti this is not the answer i want Commented Jul 27, 2017 at 7:20
  • [HttpPost] public async Task<IActionResult> Upload(ICollection<IFormFile> files, FormCollection form) {var inputForm = form["inputForm"];} let say this is how to get the form, but i am wanting the data from the <input> value attribute Commented Jul 27, 2017 at 7:22

2 Answers 2

0

you can use

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

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

Sign up to request clarification or add additional context in comments.

3 Comments

how i get that in controller?
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.
This is what you need i think. same question.. [link] (stackoverflow.com/questions/14124324/…)
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">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.