2012-09-07 8 views
10

MVCカミソリを初めて使いました。このメソッドを呼び出しますMVCカミソリボタンクリックしてパラメータを渡します

@model SuburbanCustPortal.Models.CustomerModel 

@{ 
    ViewBag.Title = "Customer Summary"; 
} 

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

<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.") 

    <div> 
    <fieldset> 
     <legend>Existing Accounts</legend> 

     @Html.Action("ExistingAccounts2") 

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


    </fieldset> 
    </div> 
} 

私はこの見解を持っている

今度はこの部分図呼び出す
[Authorize] 
public ActionResult ExistingAccounts2() 
{ 
    return PartialView("ExistingAccounts", _client.RequestCustomersForAccount(User.Identity.Name)); 
} 

@model IEnumerable<SuburbanCustPortal.SuburbanService.CustomerData > 

<br /> 
<br /> 
<table> 

    @if (Model != null) 
    { 
    foreach (var usr in Model) 
    { 
     <tr>  
     <td> 
      <input id="btnShowCustomer" name="btnShowCustomer2" type="submit" value="View"/>   
     </td> 
     <td> 
      @usr.AccountId 
     </td> 
     <td> 
      @usr.Name 
     </td> 
@*  <td> 
      @usr.DeliveryStreet 
     </td>*@ 
     </tr> 
    } 
    } 

</table> 
<br /> 

これを表示し終わる:

enter image description here

これまでのところこれまでの動作です。

お客様の名前の横にあるボタンをクリックすると、顧客のアカウントが表示されます。

どのようにしてその顧客をボタンに結びつけ、誰がプルアップするのかを知ることができます。どのようにしてボタンをクリックしてプルアップするのですか?

答えて

7

あなたはボタンがクリックされると、バック顧客番号を渡す必要があります。

あなたがモデルでプロパティとして顧客番号を持っている場合は、あなたが何か行うことができます:@Htを使用してサーバーに

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

あなたは可能性があり、その後POSTこのデータをAjax.ActionLink、またはjQueryの@ ml.ActionLink、:

アクションリンク

@Html.ActionLink("LoadInfo", "Info", new {[email protected]}) 

jQueryの

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

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

     } 
}); 
+0

エラーが発生しました - 「data-customerNumberは要素入力に有効な属性ではありません」 –

+0

コントローラでこの情報を取得する方法はありますか? – Danieboy

-1

これはトリックを行うと思います! OID顧客のID(私はパスが:) OKだと思ういけない)

@Ajax.RawActionLink("Action", "Controller", new { oid = '@Model.customerID'}, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "the view you want to show" }, new { id = "btnNewB", @class = "your btn class" }) 

幸運でしょう;)

+0

はシンボル "RawActionLink" を解決できません。 RawActionLinkを見るにはどうすればいいですか? – ErocM

+0

うーん...それは起こらない...あなたが得る正確なエラーは何ですか? –

+0

ビジュアルスタジオとまったく同じ:「RawActionLink」というシンボルを解決できません。 – ErocM

関連する問題