Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

View component in modal window #9072


User avatar
0
geoteam created

Hello, I'm having trouble embedding a view component into a Modal Insert/Edit form. Is it possible that this does not work? I have tried to analyze the error, but the only thing that is displayed: POST http://localhost:62114/App/Addresses/CreateOrEditAddressModal 500 (Internal Server Error) in app-layout-libs.min.js:10320

_CreateOrEditAddressModal.cshtml:

@using Zero.Addresses
@using Zero.Web.Areas.App.Models.Common.Modals
@using Zero.Web.Areas.App.Views.Shared.Components.AppModalRegTable

@model Zero.Web.Areas.App.Models.Addresses.CreateOrEditAddressModalViewModel
@await Html.PartialAsync("\~/Areas/App/Views/Common/Modals/\_ModalHeader.cshtml", new ModalHeaderViewModel(Model.IsEditMode ? (L("EditAddress") + ": " + Model.AddressPersonCompany.PersonCompanyNameCompany) : L("CreateNewAddress")))

<div class="modal-body">
    <form role="form" novalidate class="form-validation kt-form">
        .
        .
        .
     </form>
    @await Html.PartialAsync("~/Areas/App/Views/Common/Modals/_ModalFooterWithSaveAndCancel.cshtml")
</div>
<div class="modalForm__RegisterTablePartial">
    @await Component.InvokeAsync(typeof(AppModalRegisterTableViewComponent), new { registerTable = "Title" })
</div>

Default.cshtml (for testing) of Viewcomponent

@model TreasureMap.Web.Areas.App.Models.RegisterTable.RegisterTableViewModel
<div></div>

AppModalRegisterTableViewComponent:

public class AppModalRegisterTableViewComponent : ZeroMapViewComponent
    {      
        public AppModalRegisterTableViewComponent()
        {
            
        }

        public IViewComponentResult Invoke(string registerTable)
        {
            var regTableModel = new RegisterTableViewModel
            {
                DisplayName = string.Empty,
                TableName = string.Empty
            };

            return View(regTableModel);
        }        
    }

Comment out the line @await Component.Invoke... then modal window is shown. At another place (in the menu bar) I also have a ViewComponent. There it works.


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @geoteam,

    Could you check the server side log file to see error details ? It is App_Data/Logs/Logs.txt file.

  • User Avatar
    0
    geoteam created

    Hi ismcagdas, thank you for giving me the right lead. With the log it was no problem to fix the error. The name of the directory was not the same as the name of the view component. Therefore the default.cshtml was not found. Many greetings geoteam