Solved

MVC Capture the selected item id clicked by the user

Posted on 2013-02-06
7
407 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
  • 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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