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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:36:00+00:00 2026-05-26T22:36:00+00:00

This is my view: @model PhoneBook.Models.Number @{ ViewBag.Title = Create; } <h2>Create</h2> <script src=../../Scripts/jQuery.AddNewNumber.js

  • 0

This is my view:

@model PhoneBook.Models.Number
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
<script src="../../Scripts/jQuery.AddNewNumber.js" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Contact.Id)
<fieldset>
    <legend>Number</legend>
    <div class="TargetElements">
        <div class="editor-label">
            @Html.LabelFor(model => model.PhoneNumber)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.PhoneNumber)
            @Html.ValidationMessageFor(model => model.PhoneNumber)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.NumberKind)
        </div>
        <div class="editor-field">
        @Html.DropDownListFor(model => model.NumberKind.Title, NumberKinds)
        </div>
    </div>
<p>
        <input class="AddNew" value="Add New" type="button" /></p>
    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
}

I need when press the “Add New” button All the elements in <div class="TargetElements"> Copied and in when press the submit button I can achieve all values.

At now i use this script:

$(document).ready(function () {
$('.AddNew').click(function () {
    $(".TargetElements:first").clone().insertAfter('.TargetElements');
});
});

but there is 2 problem with this:
1- when I add first time one div(include target elements) added but in second time two div added and grow in ascending
2- when copy the elements all the value of target element added but I need Empty inputs to add new value

How Can I fix the Script?

And finally I don’t know how can I retrieve values of all element in my controller:

[HttpPost]
    public ActionResult Create(Number NewNumber, FormCollection collection) {
}
  • 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-05-26T22:36:01+00:00Added an answer on May 26, 2026 at 10:36 pm

    1- when I add first time one div(include target elements) added but
    in second time two div added and grow in ascending.

    You insert the new field after every field that exist, take a look at:
    $(“.TargetElements:first”).clone().insertAfter(‘.TargetElements’);

    Should be:
    $(“.TargetElements:first”).clone().insertAfter(‘.TargetElements:last’);

    2- when copy the elements all the value of target element added but I need Empty inputs to add new value

    There is no one that stops you from clearing the values with Javascript, just go through all the input elements in the new clone and clear their values.

    function cloneTargetBox() {
        var targetBoxClone = $(".target-elements:first").clone();
        targetBoxClone.find("input").val(""); //Not sure this is the proper way, but hey, it works
        targetBoxClone.insertAfter(".target-elements:last")
    }
    

    Here is a code sample of what you want to achieve: http://jsfiddle.net/KVqW8/3/

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

Sidebar

Related Questions

I have this view: @model MatchGaming.Models.ProfileQuery @{ ViewBag.Title = Index; } <h2>Index</h2> <script src=@Url.Content(~/Scripts/jquery.validate.min.js)
This may seem really silly to you, I admit, but when discussing the Model-View-ViewModel
This may be old news but back in March 2009, this article, Model-View-ViewModel In
I got a view that inherits : System.Web.Mvc.ViewPage<IEnumerable<MyProjects.Models.MyAccountWrapper>> In this view I list data
We had a View Model that looked like this: public class myViewModel { public
In the world of MVC I have this view model... public class MyViewModel{ [Required]
In a view model, I have a collection of items of type ClassA called
this is my controller: public ActionResult Create() { Number newNumber = new Number(); return
this is my controller: public ActionResult Create() { Number newNumber = new Number(); return
When I have a DropDownList that relevant to Model of view like this: @Html.DropDownListFor(model

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.