2010-11-20 7 views
1

Désolé, mon anglais est pas bon,Comment obtenir la valeur de View au contrôleur

J'ai une vue:

<div class="editor-field" id = "nick">Nick <%: Html.TextBoxFor(model => model.Nick)%><img src="/Content/Images/loading.gif" alt = "loading...."/> 
     <%: Ajax.ActionLink("Check", "Check", new AjaxOptions { UpdateTargetId = "check-valid", LoadingElementId = "loading"})%> 
     </div> 

je: Nick = ViewData.Model.Nick dans ActionLink comme ci-dessous, mais je ne peux pas obtenir la valeur de Nick de View. S'il vous plaît aidez-moi

<%: Ajax.ActionLink("Check", "Check", new {Nick = ViewData.Model.Nick}, new AjaxOptions { UpdateTargetId = "check-valid", LoadingElementId = "loading"})%> 

Répondre

0
<% using (Html.BeginFormBegin()){%> 

<div class="editor-field" id = "nick">Nick <%: Html.TextBoxFor(model => model.Nick)%><img src="/Content/Images/loading.gif" alt = "loading...."/> 
     <%: Ajax.ActionLink("Check", "Check", new AjaxOptions { UpdateTargetId = "check-valid", LoadingElementId = "loading"})%> 
     </div> 

<input type="submit" value="Submit" /> 

<%}%> 

Dans votre contrôleur votre action correspondante doit être quelque chose comme:

[HttpPost] 
public ActionResult MyForm(string nick) 
{ 
    //nick - should contain the value from the form 

    return View(); 
} 
+0

À votre avis, ActionLink ne peut pas prendre de paramètre View, non? :( – Paris

+0

J'ai bien peur de ne pas comprendre ce que vous voulez dire: j'apprécie que votre anglais ne soit pas génial :-) pouvez-vous inclure plus de code? – Rob