0

I am trying to pass a model to a bootstrap modal editor. I call the modal from an Ajax method. I can get the model from the controller, and view its properties from the script's success event. However, I cannot send this model "mod" to my bootstrap modal body. mod is always null when I call my partial view inside in my modal body. Is it possible to open/show a Bootstrap modal with a value passed to the modal-body.

@model StockItemViewModel
@{
ViewData["Title"] = "ProductServiceIndex";
StockItemViewModel mod = Model;


<div class="modal fade" id="prodserviceModal" tabindex="-1" role="dialog" aria-labelledby="myModal-label">
<div class="modal-dialog vertical-align-center">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModal-label">Product/Service Information</h4>
            <h4>@mod.StockItemName</h4>
        </div>
        <div class="modal-body" id="productServicePlaceholder">
            @await Html.PartialAsync("_ProductServiceModal", mod)
        </div>
    </div>
</div>

function ajax_get(data) {
    $.ajax({
        url: "/Purchasing/AddEditProdServ",
        type: "GET",           
        data: data,
        success: function (data) {
            //$('#productServicePlaceholder').html(data);
            mod = data;
            //alert(mod.StockItemId);
            $('#prodserviceModal').modal('show');
        }
    });  
4
  • stackoverflow.com/questions/39865828/… Commented Dec 14, 2018 at 16:38
  • Try returning the partial view itself from your ajax function: stackoverflow.com/questions/10589787/… Commented Dec 14, 2018 at 17:15
  • While I would also return the partial view from the ajax as an html string then use $("#productServicePlaceHolder").html(data), you can set individual inputs based on the data returned (none of which is in the question, so here's an example): $("#productServicePlaceholder #ProductTitle").val(data.ProductTitle) Commented Dec 14, 2018 at 18:27
  • Ideally, I will like to just set the model in my partialasync call to the model returned from the controller. Is this possible? Each time I try it using the code provided earlier, my mod is returning null. Commented Dec 15, 2018 at 17:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.