Solved

MVC Capture the selected item id clicked by the user

Posted on 2013-02-06
7
418 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

860 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