vendredi 31 juillet 2015

MVC: Send parameters to method by a button

I have the following button in a View

    <button id="Export" class="btn btn-default custom" type="button">
          <i class="glyphicon glyphicon-file"></i>Export to Excel
    </button>

And I want it to export a list of materials that I have in a ViewData

I already have the logic. The code could be in a ActionResult or a normal method and it would be something like this:

    [HttpPost]
    public void Export(List<int> listPassed)
    {
           //stuff here
    }

I tried adding href="@Url.Action("Export", "Materials", new { export_documentation = true })" but it didn't work out.

I could do it with an override of the ActionLink method but I would lose the glyphicon. Thing that I want to avoid. Overrides of the ActionLink that tricks the helper to have a glyphicon also didn't work out.

I tried Ajax but I suck at jscript and ajax and all that stuff at the moment.

So, how can send the parameters to the method?

Aucun commentaire:

Enregistrer un commentaire