Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9126641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:05:16+00:00 2026-06-17T07:05:16+00:00

A little behind the problem and what I am trying badly to do. I

  • 0

A little behind the problem and what I am trying badly to do. I basically have a form which places data in my viewModel. The trouble is, say a customer company is at one address but the contact is at another address I want the user to be able to click on a radio button that is on the main form they are filling out, type in the contacts different address and save this into the model that I have on the main form.

I have a controller which does the following:

    [HttpPost]
    public ActionResult Edit(ClientModel client)
    {
        Domain.Data.EFDbContext context = new Domain.Data.EFDbContext();
        if (ModelState.IsValid)
        {
            client.ClientAddress.AddressTypeId = client.AddressType.AddressTypeId;
            client.Contact.ContactTypeId = client.ContactType.ContactTypeID;

            //Add the address to the ContactAddress table and Contact ID
            if (client.ContactAddress.AddressLine1 != null)
            {
                client.Contact.ContactAddress.Add(client.ContactAddress);
                context.Contacts.Add(client.Contact);
            }
            else
            {
                client.ContactAddress = client.ClientAddress;
            }
            client.Company.Address.Add(client.ContactAddress);
            client.Company.CompanyContact.Add(client.Contact);

            //The attachment to Client is created on a Trigger in the database when a new Company is added
            context.Companies.Add(client.Company);
            context.SaveChanges();

            return RedirectToAction("Index");
        }
        else
        {
            return View(client);
        }
    }

This works fine, it updates my database tables and saves the result, but I have added in the client.ContactAddress part, so if it knows a field is empty from my form it just assigns the company address to where the client is and saves that in the relevant field. (This is not the issue though, just back ground)

I have tried to create a partialView and in the controller

    [HttpGet]
    public PartialViewResult AddressPartial()
    {
        return PartialView("_AddressPartial");
    }

and in my edit.aspx I have

$(document).ready(function () {
    $('#Not_Contact_Address').click(function (e) {
        if ($('#Not_Contact_Address').is(':checked')) {

            $('#dialog').dialog({
                autoOpen: false,
                width: 400,
                resizable: false,
                title: 'Add Address',
                modal: true,
                open: function(event, ui) {
                //Load the AddressPartial action which will return 
                // the partial view _AddressPartial
                   $(this).load("@Url.Action("AddressPartial")");
                },
                buttons: {
                    "Save": function() {
                        $('#dialog').dialog('close');
                    },
                    "Cancel": function () {
                        $('#dialog').dialog('close');
                    }
                }
            });

            $('#dialog').dialog('open');
        }
    });
});

Basically, a user selects a radio button, a Add Address dialog pops up, I want the user to add that information in and then display this information back on the form below the radio button selected, and then they can carry on and once completed hit the Submit button and save all the information right away to the database. (Shown in controller above).

<fieldset>
    <legend>Main Contact Details</legend>
    <div class="editor-label">
        @Html.LabelFor(model => model.Contact.Title)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Contact.Title)
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.Contact.FirstName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Contact.FirstName)
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.Contact.LastName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Contact.LastName)
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.Contact.Email)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Contact.Email)
    </div>
     <div class="editor-label">
        @Html.LabelFor(model => model.Contact.Phone)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Contact.Phone)
    </div>
     <div class="editor-label">
        @Html.LabelFor(model => model.Contact.Mobile)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Contact.Mobile)
    </div>
    <div class="editor-label">
         @Html.LabelFor(model => model.ContactType.Name)
    </div>
    <div class="editor-field">
         @Html.DropDownListFor(model => model.ContactType.ContactTypeID, Model.ContactSelectList, " --- Select One --- ", null)
    </div>  

    <b>Contact Address</b> same as <b>Company Address</b> @Html.RadioButton("Not_Contact_Address", "Yes") Yes @Html.RadioButton("Not_Contact_Address", "No") No
</fieldset>

Problems

I can open the dialog which is fine, but I cannot cancel the dialog box, I click the x on the top right corner and this then blanks my entire form and left with blank page, not what I want.

What is the best way to go about have a form, so that a user can enter information on a form, display another form within the page to add address and save that to the viewModel I have and then allow the user to carry on.

UPDATED

function openProductEditDialog() {

    $("#ProductDetailsDialogDiv").html("");

    $.ajax({
        type: "GET",
        url: encodeURI('@Url.Action("AddressPartial", "Home")'),
        cache: false,
        dataType: 'html',
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $("#ProductEditDialogDiv").html(XMLHttpRequest.responseText);
        },
        success: function (data, textStatus, XMLHttpRequest) {
            $("#ProductEditDialogDiv").html(data);
        },
        complete: function (XMLHttpRequest, textStatus) {

            $('#ProductEditDialogDiv').dialog({
                width: '500px',
                modal: true
            });
        }
    });
}

This allows me to now save the information in a new window and return back to my screen, any idea’s how to save this the viewModel on the main page. I want the AddressPartial to be put into my viewModel on the CreateClient page where it was called so they can carry on with the form and not lose any information.

I am guessing that I should point this at the controller and tell it to resend the viewModel with the ContactAddress back to the CreateClient page. Working on this at the moment.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:05:17+00:00Added an answer on June 17, 2026 at 7:05 am

    You could save the address with an Ajax request and return the key. Then save the key in a hidden input box in the original form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Little help if you don't mind. Basically, I have 3 radio boxes and a
Little Background: I have csv file which has lots of rows and each row
Little trouble in using css, in the below code, i have used odd and
A little background: I have a perl script which is performing a number of
I have a little problem and I'm hopping that you can help me solve
I find this as a funny little problem. I think the reason lies behind
I have a little problem with my dynamically created controls. I have a asp.net
Background I've been struggling with this stupid little problem of trying to cancel link
enter code here I am having a little problem with jquery.empty(). I have some
I have a little problems understand what's going on behind the scenes of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.