Solved

MVC Capture the selected item id clicked by the user

Posted on 2013-02-06
7
412 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hangfire / asp.net sample 3 50
asp.net bundle 8 47
c# regex: extract & replace text between braces 6 45
ASP.NET Core index.html  LOCALHOST page cannot be found 2 25
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

24 Experts available now in Live!

Get 1:1 Help Now