asp mvc 4 c#

Hello Everyone
  I  have a dialog box on my application that is populated with a single row of data. My goal is to do either of the following
  1) add a radio button next to each item so I can select it
                or
  2) make each item in the list  a link to a c# procedure so I click it and add the selected item to the database
need-click.docx
vcurtisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ioannis ParaskevopoulosCommented:
Hi,

I think there are multiple ways of doing that.

1.


Have a select tag:

In cshtml
@Html.ListBoxFor(m => m.CommitteeCode, (new SelectionList(Model.CommitteeList.CommitteeList,"CommitteeCode","CommitteeName"), new { @onchange = "CommitteeChanged(this.options[this.selectedIndex].value);" })
<script>
    function CommitteeChanged(value) {
        window.location.href = '/YOURCONTROLLERNAME/CommitteeChanged/?id=' + value;
}
</script>

Open in new window


In your controller

public ActionResult CommitteeChanged(string id)
{
       //Call Your Sp
       return RedirectToAction("Index");//I just guess that your main Action is Index, you may change that to reflect your needs.
}

Open in new window


The above will do a postback, so you will get your page refreshed.

2.


Another way would be wrapping your code in a form and posting it:

In cshtml

@using (Html.BeginForm("CommitteeChanged", "Committee", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <fieldset>
        <div>
            @Html.DisplayFor(modelItem => item.CommitteeName)	
            @Html.ListBoxFor(m => m.CommitteeCode, (new SelectionList(Model.CommitteeList.CommitteeList,"CommitteeCode","CommitteeName"), new { @onchange = "CommitteeChanged(this.options[this.selectedIndex].value);" })
            <input type="submit" value="Submit" />
        </div>
        
    </fieldset>
}

Open in new window


public ActionResult CommitteeChanged(string CommitteeCode)
{
       //Call Your Sp
       return RedirectToAction("Index");//I just guess that your main Action is Index, you may change that to reflect your needs.
}

Open in new window


A more complex way would be using javascript to do your post and avoid refreshing, but i am not too well into it and i wouldn't like to comment on that.

Giannis
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vcurtisAuthor Commented:
Thank you so much Giannis, You were right on track with this one
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.