Skip to content
Loading
get data from controller in view in mvc  
  •                               
  •                             class="card custom_card" style="width: 17rem;">  
  •                                   @Html.Action("TopSixByBrand""Home"new {_brand = item.Brand })  
  •                                 class="card-body custom_card_body d-flex justify-content-between px-2 py-2">  
  •                                     class="row-col-lg-2 f_500 t_color2 f_size_16">class="card-name mb-0">@item.modelYear

      
  •                                     class="row-col-lg-2 f_500 t_color f_size_20">class="card-price mb-0">@item.expectedPrice

      
  •                                   
  • }  
  • I hope, you have brand names in model. 
  • Sachin Singh
    i am using your way i get the data but i want it in a foreach loop 
  • Gajendra Jangid
    HI Garima,
     
    You can check following resource. it may help you to find solution.
     
    https://www.c-sharpcorner.com/article/asp-net-mvc-passing-data-from-controller-to-view/#:~:text=from%20the%20ViewData.-,The%20other%20way%20of%20passing%20the%20data%20from%20Controller%20to,model%20class%20in%20return%20view.&text=Import%20the%20binding%20object%20of,access%20the%20properties%20by%20%40Model. 
  • Sachin Singh
    You have multiple options 
    as you are using tabs you can directly call your partial method
    1. class="tab-pane fade" id="nav-hyundai" role="tabpanel" aria-labelledby="nav-hyundai-tab">  
    2.                         @Html.Action("TopSixByBrand"new {_Brand="Hundai"})  
    3. class="text-center mt_50 mb-30">  
    4.   
    5. class="tab-pane fade" id="nav-honda" role="tabpanel" aria-labelledby="nav-honda-tab">  
    6.                         @Html.Action("TopSixByBrand"new {_Brand="Honda"})  
    7. class="text-center mt_50 mb-30">  
    or, The way you are doing, means, through ajax is also correct. 
  • Muhammad Imran Ansari
    Check this article:
    https://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/various-ways-to-pass-data-from-controller-to-view-in-mvc/