如何从View到Controller获取价值

时间:2010-11-20 03:08:26

标签: asp.net asp.net-mvc ajax helper

抱歉,我的英语不好,

我有一个观点:

<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>

我在ActionLink中使用了Nick = ViewData.Model.Nick,如下所示,但我无法从View获得Nick的价值。请帮帮我

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

1 个答案:

答案 0 :(得分: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" />

<%}%>

在您的控制器中,您的相应操作应该是:

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

    return View();
}