Solved

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

Posted on 2012-04-07
5
504 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

696 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