Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-04-07
5
Medium Priority
?
508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. 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 :…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
Suggested Courses

610 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