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

The Archive Base Latest Questions

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

I have the following View inside my ASP.Net mvc 3 web application:- @model IEnumerable<MvcApplication4.Models.Account>

  • 0

I have the following View inside my ASP.Net mvc 3 web application:-

@model IEnumerable<MvcApplication4.Models.Account>

@{
    ViewBag.Title = "customer";
}

<h3>Customers Info</h3>


    <script  type="text/javascript">

        $(function() {

            $("#MoveRight,#MoveLeft").click(function(event) {

                var id = $(event.target).attr("id");

                var selectFrom = id == "MoveRight" ? "#SelectLeft" : "#SelectRight";

                var moveTo = id == "MoveRight" ? "#SelectRight" : "#SelectLeft";



                var selectedItems = $(selectFrom + " :selected").toArray();

                $(moveTo).append(selectedItems);

                selectedItems.remove;

            });

        });

    </script>  

      <select id="SelectLeft" multiple="multiple">
 @foreach (var item2 in Model.OrderBy(a=>a.ORG_NAME)) {
            <option value = "@item2.ORG_ID" >@item2.ORG_NAME</option>




}
      </select>      

    <input id="MoveRight" type="button" value=" Add >> " />

  <input id="MoveLeft" type="button" value=" << Remove " /> 

      <select id="SelectRight" multiple="multiple">           

      </select>
 @Html.ActionLink("Next Page", "CustomersDetials", "Home", new {  }, null)//for testing only

But I am facing a problem in that I need to pass all the records which are inside the moveTo to the customersDetials action method by clicking on the “Next Page” action link. so can anyone suggest an approach which I can use to pass the items which are inside the moveto from my above view to my action method using the html.actionlink.

:::UPDATE:::

I have added the following to the view:-

@using (Html.BeginForm("CustomersDetials", "Home"))
{

      <select id="SelectLeft" multiple="multiple">
 @foreach (var item2 in Model.OrderBy(a=>a.ORG_NAME)) {
            <option value = "@item2.ORG_ID" >@item2.ORG_NAME</option>


}
      </select>      

    <input id="MoveRight" type="button" value=" Add >> " />

  <input id="MoveLeft" type="button" value=" << Remove " /> 



      <select id="SelectRight" name="SelectRight" multiple="multiple">           

      </select>
    <p>
<button type="submit">Next Page</button></p>

}

And then i have created the folloiwng ViewModel class to hole the values of the selected customers:-

public class SelectedCustomers
{
    public IEnumerable<Account> Info { get; set; }
}

then i added the folloiwng action method:-

   public ActionResult CustomersDetials(string[] SelectRight)
        {
             foreach (var item in SelectRight) {

                // how to assign the values of the array to my viewmodel object       
        }

But i can not determine how i can assign the values of the array to the viewmodel object inside my action method.

:::UPDATE2:::

Here what i have ended up with. the action method looks like this:-

    public ActionResult CustomersDetails(string[] SelectRight)
        {
            var selectedCustomers = new SelectedCustomers
            {
                Info = SelectRight.Select(GetAccount)
            };


        return View(selectedCustomers);

    }
    private Account GetAccount(string id)
    {


        return entities.Account.Find(id);
    }
}

And the folloiwng view:-

@model MvcApplication4.Models.SelectedCustomers

@{
    ViewBag.Title = "CustomerDetials";
}

<h2>CustomerDetials</h2>
//code goes here

@foreach (var item in Model.Info) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.ORG_ID)
        </td>

but when i run the application i got the folloiwng error :-

The type of one of the primary key values did not match the type defined in the entity. See inner exception for details.

On the:-

return entities.Account.Find(id);

::Solved::
i changed the string to be long in both the action method and GETAccount function.

  • 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-16T07:51:55+00:00Added an answer on June 16, 2026 at 7:51 am

    You could make the Next link a submit button of the form. Then when the form is submitted it will automatically send the selected items of the select lists to the server. It’s the solution I would recommend you. Just put the select lists into a form and also don’t forget to give your select lists names because that’s what you will use in your controller action to retrieve the selected values:

    @using (Html.BeginForm("CustomersDetials", "Home"))
    {
        <select id="SelectLeft" name="SelectLeft" multiple="multiple">
            @foreach (var item2 in Model.OrderBy(a => a.ORG_NAME)) 
            {
                <option value="@item2.ORG_ID">@item2.ORG_NAME</option>
            }
        </select>
    
        <select id="SelectRight" name="SelectRight" multiple="multiple">           
        </select>
    
        <button type="submit">Next Page</button>
    }
    

    And by the way instead of doing those horrible foreach loops in your view to generate those multiple selectboxes you could use the built-in Html.ListBoxFor helper.

    Now your controller action could look like this:

    [HttpPost]
    public ActionResult CustomersDetials(string[] selectRight)
    {
        ... the selectRight parameter will contain the selected values in the 
            corresponding select list
    }
    

    Another possibility to handle this case is to use AJAX:

    @Html.ActionLink("Next Page", "CustomersDetials", "Home", null, new { id = "next" })
    

    and then:

    $('#next').click(function() {
        $.ajax({
            url: this.href,
            type: 'POST',
            contentType: 'application/json;charset=utf-8',
            data: JSON.stringify(selectedItems),
            success: function(data) {
    
            }
        });
        return false;
    });
    

    Of course you need to make selectedItems a global variable, because right now you have declared it inside the click handler of the MoveRight, MoveLeft buttons. Otherwise this variable won’t be accessible within the click event of the next link.


    UPDATE 1:

    Based on your update you could populate your view model like this:

    public ActionResult CustomersDetials(string[] selectRight)
    {
        var selectedCustomers = new SelectedCustomers
        {
            Info = selectRight.Select(GetAccount)
        };
        ... use your view model here
    }
    
    private Account GetAccount(string id)
    {
        // TODO: given the selected ID go and fetch the corresponding
        // Account instance and return it here:
    
        return new Account
        {
            Id = id
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following view inside my asp.net MVC web application:- <table id=tablelist border=1>
i have the following script inside my asp.net MVC application to bounce the image
i have the following Ajax.beginform inside my asp.net mvc view, where the result of
i have the following script inside my asp.net mvc view:- function disableform(id) { $('#'
I have the following view definition in my asp.net mvc website: <% Using Ajax.BeginForm(UsrCtlChangePassword,
I am working on an asp.net mvc web application and i have the folloiwng
i have the folloiwng action method inside my asp.net mvc application:- public ActionResult CustomersDetails(long[]
I have the following view: @model MyModel1 @{ ViewBag.Title = Index; Layout = ~/Views/Shared/_Layout.cshtml;
using ASP.NET MVC 2 I have a navigation menu inside my Master Page. In
Hallo, I have following jquery code for calling ASP.NET MVC controller method that is

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.