Solved

MVC3 post back a specific Id from a  list of similar items by clicking the list item

Posted on 2012-04-07
5
496 Views
Last Modified: 2012-04-08
I have two lists on a Page.  The items of each list are identified by an Id.  I want to select a list item pass the Id back to the server.  What is the best way?
0
Comment
Question by:ddefreitas
  • 3
  • 2
5 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 37819700
It would help if you showed some code or posted a link.


Cd&
0
 

Author Comment

by:ddefreitas
ID: 37819885
The bones of the cshtml page code file goes like this and basically I want to be able to allocate the Id of a list 1 item to one or more items in list 2.  



<ul>
   

@foreach (var item in Model.HeadingsList1) {
    <li>
            <input type="checkbox" name="add" />Id: @item.Id  @item.Name
           
        </li>
}

</ul>

<ul>
   

@foreach (var item in Model.List2) {
    <li>
            <input type="checkbox" name="add" />Id: @item.Id  @item.Name
           
        </li>
}

</ul>

producing

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Lists</title>
</head>

<body>
      <ul>
      <li>
        <input type="checkbox" name="add" />Id: 1  Item 1 from list 2
      </li>
      <li>
        <input type="checkbox" name="add" />Id: 2  Item 2 from list 2
      </li>
      <li>
        <input type="checkbox" name="add" />Id: 3  Item 3 from list 2
      </li>
      <li>
        <input type="checkbox" name="add" />Id: 4  Item 4 from list 2
      </li>
      <li>
        <input type="checkbox" name="add" />Id: 5  Item 5 from list 2
      </li>
    </ul>

    <ul>
      <li>
        <input type="checkbox" name="add" />Id: 1  Item 1 from list 1
      </li>
      <li>
        <input type="checkbox" name="add" />Id: 2  Item 2 from list 1
      </li>
      <li>
        <input type="checkbox" name="add" />Id: 3  Item 3 from list 1
      </li>
      <li>
        <input type="checkbox" name="add" />Id: 4  Item 4 from list 1
      </li>
      <li>
        <input type="checkbox" name="add" />Id: 5  Item 5 from list 1
      </li>
    </ul>

      <input name="Add" type="submit" value="add">

</body>
</html>
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 37819941
Put the inputs an submit into a form.  Give the form a "post" method, and set the action to point at the server side script that handles the update or whatever action you are doing.  If you don't want a page refresh then set the action of the form to a javascript function that goes across to the server using AJAX.

Cd&
0
 

Author Comment

by:ddefreitas
ID: 37821009
I have enclosed the inputs and submits in a Html.BeginForm() and can get the Id back in the controller but the Checkbox doesn't show.  How would I identify which items have been selected?
0
 

Author Comment

by:ddefreitas
ID: 37821694
I have now solved my checkbox id issue as well so thanks for the steer onto the right path
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now