0

我正在使用 MVC 3,在我的项目中我有 2 个视图,我想在第一个视图弹出窗口中打开第二个视图

我的第一个视图是我想在弹出窗口中打开第二个视图,

@model CustomerAddressListModel
@using Nop.Web.Models.Customer;
@{
Layout = "~/Views/Shared/_ColumnsTwo.cshtml";

//title
Html.AddTitleParts(T("PageTitle.Account").Text);
}


    <script type="text/javascript">
        $(function () {
            $('a.dialog').click(function () {
                var url = $(this).attr('href');
                var dialog = $('<div style="display:none"></div>').appendTo('body');
                dialog.load(url, {}, function (responseText, textStatus, XMLHttpRequest) {
                    dialog.dialog({
                        close: function (event, ui) {
                            dialog.remove();
                        }
                    });
                });
                return false;
            });
        });
  </script>


    <div class="add-btn-cntrnr left" style="width:400px;">

        @Html.ActionLink("AddLink", "AddressAdd", "Customer", new { @class = "dialog" })

    </div>

这是我想在 PopUp 中打开的第二个视图:

@model CustomerAddressEditModel
@using Nop.Web.Models.Customer;
@{
Layout = null;
}
@using Nop.Web.Framework;


  @using (Html.BeginForm())
   {

   <div class="emai_head">

    <span class="emai_head_text">Add Address</span>
    @{
    var dataDictAddress = new ViewDataDictionary();
    //Merge ModelState (required for validation)
   dataDictAddress.ModelState.Merge(ViewData.ModelState);
   dataDictAddress.TemplateInfo.HtmlFieldPrefix = "Address";
            @Html.Partial("_CreateOrUpdateAddress", Model.Address, dataDictAddress)              
    }
    <input type="submit" class="acc_btnn" value=" " />
    </div>
    }

这是我的弹出视图控制器:

        [NopHttpsRequirement(SslRequirement.Yes)]
    public ActionResult AddressAdd()
    {
        if (!IsCurrentUserRegistered())
            return new HttpUnauthorizedResult();

        var customer = _workContext.CurrentCustomer;

        var model = new CustomerAddressEditModel();
        model.NavigationModel = GetCustomerNavigationModel(customer);
        model.NavigationModel.SelectedTab = CustomerNavigationEnum.Addresses;

        model.Address = new AddressModel();
        //countries
        model.Address.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" });
        foreach (var c in _countryService.GetAllCountries())
            model.Address.AvailableCountries.Add(new SelectListItem() { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString() });
        model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.OtherNonUS"), Value = "0" });

        return View(model);
    }

    [HttpPost]
    public ActionResult AddressAdd(CustomerAddressEditModel model)
    {
        if (!IsCurrentUserRegistered())
            return new HttpUnauthorizedResult();

        var customer = _workContext.CurrentCustomer;

        model.NavigationModel = GetCustomerNavigationModel(customer);
        model.NavigationModel.SelectedTab = CustomerNavigationEnum.Addresses;

        if (ModelState.IsValid)
        {
            var address = model.Address.ToEntity();
            address.CreatedOnUtc = DateTime.UtcNow;
            //some validation
            if (address.CountryId == 0)
                address.CountryId = null;
            if (address.StateProvinceId == 0)
                address.StateProvinceId = null;
            customer.Addresses.Add(address);
            _customerService.UpdateCustomer(customer);

           // return RedirectToRoute("CustomerAddresses");
        }


        //If we got this far, something failed, redisplay form
        //countries
        model.Address.AvailableCountries.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" });
        foreach (var c in _countryService.GetAllCountries())
            model.Address.AvailableCountries.Add(new SelectListItem() { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = (c.Id == model.Address.CountryId) });
        //states
        var states = model.Address.CountryId.HasValue ? _stateProvinceService.GetStateProvincesByCountryId(model.Address.CountryId.Value).ToList() : new List<StateProvince>();
        if (states.Count > 0)
        {
            foreach (var s in states)
                model.Address.AvailableStates.Add(new SelectListItem() { Text = s.GetLocalized(x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.Address.StateProvinceId) });
        }
        else
            model.Address.AvailableStates.Add(new SelectListItem() { Text = _localizationService.GetResource("Address.OtherNonUS"), Value = "0" });

        return View(model);
    }
4

0 回答 0