Home > front end >  Pass value from anchor to controller
Pass value from anchor to controller

Time:09-27

How can I pass the value of name.report to the controller withoout passing it through a URL, this is in a side bar. I'm sorry if this is a really simple question, but I have searched quite a lot and couldn't find a solution

                        
   @foreach (var name in Model.namesReport)
   {

       <li href="#" class=""><a class="menu_name">   @name.ReportName</a>
   }
   
       

CodePudding user response:

you can try something like this

<li><a asp-controller="controller" asp-action="action" asp-route-id = "@name.ReportName" class="menu_name"> report name </a></li>

CodePudding user response:

Controller

 [HttpPost]
        public ActionResult test(int? id) 
        {
            return null;
        }

Ajax call


        $("getReport".click(function()  {
            $ajax({
                url: '/Home/test',
                type:'POST',
                datatype: 'json',
                data: {id:"test"}


            });


        });
  • Related