There is a view of this kind
<div class="ui three stackable cards"> @foreach (var s in Model.Suppliers) { <div class="ui card link"> <div class="content"> <div id ="go" style="display:none" >@s.SupplierID</div> <h2 class="header">@s.ShortName</h2> <div class="meta" style="font-size: 0.92857143rem; "> <span style="color:black">@s.Name</span><br /> <span>ИНН: @s.Inn</span> </div> <div style="font-weight:700; font-size: 0.92857143rem; margin-top:1em;"> @foreach (var ph in s.Phones) { <i class="phone icon"></i> @ph.PhoneNumber<br /> } @foreach (var em in s.Emails) { <a href="mailto:@em.Contact_Email" target="_top"><i class="mail icon"></i>@em.Contact_Email</a><br /> } <a href="http://@s.Site" target="_blank"><i class="world icon"></i>@s.Site</a> <br /> </div> </div> </div> } </div>
It turns out such a representation
It is necessary that by clicking on the card a modal window appears with the details of the supplier.
To do this, I need to pass an Id to the controller, so in the view I created a hidden div with the Id of the producer
<div id ="go" style="display:none" >@s.SupplierID</div>
Then I get the request by passing to the controller Id. I wrote this function for this purpose.
function get(){ $('.card').click(function () { $('.navbar-fixed-top').css("z-index", "1"); var id = $("#go", this).text(); var xhr = new XMLHttpRequest(); xhr.open("GET", '/Supplier/Details/'+ id, true) xhr.send(); }); };
Everything works fine. The controller looks like this.
[HttpGet] public ActionResult Details(int id) { var supplier = db.Suppliers.Find(id); if (supplier == null) { return HttpNotFound(); } return PartialView("_Supplier_Details", supplier); }
Maybe I didn’t correctly come up with the whole scheme with hidden layers, maybe there are other simple options, I will be glad to help.
But the main problem is how you see above in the controller I transfer the model to a partial view, which should be a modal window. How to call him I do not know, I have a dead end. While I created _Supplier_Details
and put the modal window code there. So what is next? What are my steps?
Most likely, it is necessary to add a call to this modal window to the get function after the end of the request, but how can I refer to it in the separate file as a partial view.
jQuery
and in thesuccess
handler insert the answer into your modal window$('#modal .my-content').html(response)
and call the display of this window. - Andrew B