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 9085165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:10:45+00:00 2026-06-16T21:10:45+00:00

I am using asp.net mvc 4 Is there a way to update the form

  • 0

I am using asp.net mvc 4
Is there a way to update the form based on selection made by the user?

(in this case I want to fill in address fields if something is picked from the dropdown list, otherwise a new address would need to be typed in)

My model:
public class NewCompanyModel
{

    [Required]
    public string CompanyName { get; set; }
    public bool IsSameDayRequired { get; set; }

    public int AddressID { get; set; }
    public Address RegisterOfficeAddress { get; set; }
}

View:

@model ViewModels.NewCompanyModel


@using (Html.BeginForm(null, null, FormMethod.Post, new { name = "frm", id = "frm" }))
{
@Html.ValidationSummary(true)

<fieldset id="test">
    <legend>Company</legend>


        <h2>Register office address</h2>

        <div class="editor-label">
            @Html.LabelFor(model => model.AddressID)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.AddressID, (IList<SelectListItem>)ViewBag.Addresses, new {id = "address", onchange = "window.location.href='/wizard/Address?value=' + this.value;" })
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.RegisterOfficeAddress.BuildingNameOrNumber)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.RegisterOfficeAddress.BuildingNameOrNumber)
            @Html.ValidationMessageFor(model => model.RegisterOfficeAddress.BuildingNameOrNumber)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.RegisterOfficeAddress.StreetName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.RegisterOfficeAddress.StreetName)
            @Html.ValidationMessageFor(model => model.RegisterOfficeAddress.StreetName)
        </div>

and controller:

 public ActionResult Address(string value)
    {
      //get the address from db and somehow update the view
    }

The question is how do you update the ‘model.RegisterOfficeAddress.StreetName’ etc
Just to make clear this is just part of the form so I cannot submit it just yet.

Many thanks

  • 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-16T21:10:46+00:00Added an answer on June 16, 2026 at 9:10 pm

    Thanks for your help; I have decided to take a different approach:
    On dropdown change I submit the form:

    <div class="editor-label">
            @Html.LabelFor(model => model.ServiceAddress.AddressID)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.ServiceAddress.AddressID, (IEnumerable<SelectListItem>)ViewBag.Addresses, new { onchange = "this.form.submit();" })
            @Html.ValidationMessageFor(model => model.ServiceAddress.AddressID)
        </div>
    

    and then in controller:

      [HttpPost]
            public ActionResult NewDirector(NewDirectorVM vm, string value)
            {
                ModelState.Clear();
                if (vm.ServiceAddress.AddressID > 0)
                {
                   //Updates the properties of the viewModel
                   vm.ServiceAddress = _Repository.GetAddress(vm.ServiceAddress.AddressID);
                }
       return View("NewDirector", vm);
    }
    

    Please notice ModelState.Clear(); which actually allows the view to be updated from the controller (otherwise all the changes made the the viewModel by the controller would have been overwritten by the values in the view).

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

Sidebar

Related Questions

Using ASP.Net MVC 2, is there any way to use the RedirectToAction() method of
Regarding separations of concerns only, are there advantages of using ASP.NET MVC instead of
I'm using the Contrib Grid for ASP.NET MVC and I was wondering if there
I'm using ASP.NET MVC and I'd like all user entered string fields to be
I am using asp.net MVC 4, I'd like to do something like this in
I'm using ASP.NET MVC in a project and I have a requirement like this..
So a request is made to an ASP.net MVC controller/action. This has an associated
Is there a way to force use of a named route in ASP.NET MVC
We are using ASP.net MVC. Which of these is the best DI framework Ninject
Using ASP.Net MVC on my Site.Master I have: <head runat=server> <title><asp:ContentPlaceHolder ID=TitleContent runat=server />

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.