MVC Razor button click even pass parameter with it

I'm new to MVC Razor.

I have this view:

@model SuburbanCustPortal.Models.CustomerModel

    ViewBag.Title = "Customer Summary";

<h2>Customer Summary Screen</h2>
    Please select an account below or add an existing account.

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm())
  @Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.")

      <legend>Existing Accounts</legend>


        <input type="submit" value="Add an Account" />


Which calls this method:

public ActionResult ExistingAccounts2()
  return PartialView("ExistingAccounts", _client.RequestCustomersForAccount(User.Identity.Name));

Which in turn calls this partial view:

@model IEnumerable<SuburbanCustPortal.SuburbanService.CustomerData >

<br />
<br />

  @if (Model != null)
    foreach (var usr in Model)
          <input id="btnShowCustomer" name="btnShowCustomer2" type="submit" value="View"/>           
@*        <td>

<br />

Which ends up displaying this:

This works up to this point.

What I want to so is be able to click on the button next to the customer's name and it pull up the customer's account.

How do I tie that customer to the button to know who to pull up and how do have the button click pull it up?


You need to pass the Customer Number back once the button is clicked:

If you have the customer number as a property in the Model you could do something like:

<input id="btnShowCustomer" data-customerNumber="@usr.CustomerNumber" />

You could then POST this data to the Server using an @Html.ActionLink, @Ajax.ActionLink, or jQuery:

Action Link

@Html.ActionLink("LoadInfo", "Info", new {customerId=@usr.CustomerNumber})


$("#btnShowCustomer").click(function() {

 var customerId = $("#btnShowCustomer").attr("data-customerNumber");
       type: "POST", 
       data: "customerId=" + customerId, 
       url: '@Url.Action("MyAction", "MyController")', 
       success: function (result) { 


Need Your Help

Redirect in .htaccess if file exists (cache)

apache .htaccess mod-rewrite redirect

I do not understand anything .htaccess and I need a redirection to cache.

c++ test whether double is #INF

c++ double nan

I would like to isolate the behavior when some double value is a NaN or an #INF. To detect a NaN, I test

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.