Solved

MVC Capture the selected item id clicked by the user

Posted on 2013-02-06
7
419 Views
Last Modified: 2013-05-05
First time working with MVC.  I've made good progress but I need to know how to handle the issue of capturing a specific row item the user clicked.  The attached EESelected Item_Problem Pic shows the screen.  Obviously there are more items on the screen but for simplicity I showed just one to get the point across.  When the user clicks the 'Execute' it fires the action 'Execute', as seen in the attached Code_Debug_Pic.  I need this action to contain iether the specific item and id the user clicked.  from here I need to look up corosponding records related to the item id.  the issue is how do I capture the item info from the screen when the user clicks it?

If you need more info let me know.
EE-Selected-Item-Problem.bmp
Code-Debug-Pic.bmp
0
Comment
Question by:Steve7423
[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
  • 4
  • 3
7 Comments
 
LVL 23

Assisted Solution

by:Roopesh Reddy
Roopesh Reddy earned 500 total points
ID: 38862733
Hi,

Are you using WebGrid?

If yes, http://www.dotnetcurry.com/ShowArticle.aspx?ID=655

Hope it helps u...
0
 

Author Comment

by:Steve7423
ID: 38864669
Great link, thanks.  I've got a few things done, but being green with html and views, I now need to pass the selected item to the action link.  here's the code.

 WebGrid grid = new WebGrid(Model.Where(d => d.Disc_Name == discName),selectionFieldName: "selectedRow");
       
                                   
        <pre>@grid.GetHtml(

        fillEmptyRows: false,

        alternatingRowStyle: "alternative-row",

        headerStyle: "grid-header",

        footerStyle: "foot-grid",

        mode: WebGridPagerModes.All,

        firstText: "<< First",

        previousText: "< Previous", nextText: "Next >",

        lastText: "Last >>",



        columns: new[] {  

        grid.Column("Disc_Name",header:"",canSort:false),
        grid.Column("Software", canSort:false),
        grid.Column(  

           "",  

            header: "Action",  

            format: @<text>  

                    @Html.ActionLink("Execute",   "Execute")  
                     @Html.ActionLink("Execute",   "Execute", grid.selectedrow)  


                    </text>  

                    )
                     
         })
         
         

You'll notice I've added the grid.selectedrow to the ActionLink above.  I have no idea if this is correct or how it should be done.
0
 

Accepted Solution

by:
Steve7423 earned 0 total points
ID: 38865263
roopeshreddy:  I got it working

I'd like you to copy the steps below and paste it as a comment, then I'll accept it as the answer.  why because it's important others can learn from this and EE makes it difficult to accept my own answer along with yours, without major hassle.  Ive found it's easier doing this.

1)
Set the grid to selectionfilename = "selectedRow"
Eg: WebGrid grid = new WebGrid(model, selectionFieldName: "selectedRow");

2)
add arguments to the action matching parameters of the action controller Action:
 columns: new[] {  
        grid.Column("Disc_Name",header:"",canSort:false),
        grid.Column("Software", canSort:false),
        grid.Column(  
           "",  
            header: "Action",  
            format: @<text>  
                    @Html.ActionLink("Execute",   "Execute", new {DiscName = item.Disc_Name, Software = item.Software})  
                    </text>  
                    )

3)
Add the parameters to the Action:
public ActionResult Execute(string DiscName, string Software)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38873001
Hi,

So, mark your comment as Answer then!
0
 

Assisted Solution

by:Steve7423
Steve7423 earned 0 total points
ID: 38986208
roopeshreddy: there's a problem with that.  My experience with including myself as an answer initiates the question to be removed, and I don't want to do that.  I want others to learn from what we did.  when I accept my answer the question goes to support for deletion by default.

If you know of a way so i can accept both our solutions without the question being marked for delete then I'm all ears.
0
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 38992198
Hi,

In that case, you can assign some points to me with a NOTE to Administrator!!!
0
 

Author Closing Comment

by:Steve7423
ID: 39139160
The steps outlined in my comment show exactly what the problem was so others can combine roopeshreddy's link and my comment, in order to see the connection.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

740 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