ActionLink的提交型号值型号、ActionLink

由网友(友情也存在吃醋。)分享简介:我希望我的Ajax.ActionLink传递一个ViewModel属性行动。I want my Ajax.ActionLink to pass a viewModel property to action.下面是我的ViewModel Here is my ViewModelpublic class ViewM...

我希望我的Ajax.ActionLink传递一个ViewModel属性行动。

I want my Ajax.ActionLink to pass a viewModel property to action.

下面是我的ViewModel

Here is my ViewModel

public class ViewModel
    {
        public string Searchtext { get; set; }
    }

我的.cshtml

My .cshtml

@Ajax.ActionLink("Bottom3", "Bottom3",new { name = Model.Searchtext}, new AjaxOptions
{
    HttpMethod = "POST",
    InsertionMode = InsertionMode.Replace,
    UpdateTargetId = "pointsDiv"
})

 using(Html.BeginForm("Bottom3", "Home", FormMethod.Get))
     {
         @Html.TextBoxFor(x => x.Searchtext)
         <button type="submit">Search</button>
     }
    <div id="pointsDiv"></div>
}

我的控制器行动:

My Controller action:

public PartialViewResult Bottom3(string name)
        {
            var model = db.XLBDataPoints.OrderBy(x => x.DataPointID).Take(3).ToList();

            return PartialView("Partial1", model);
        }

但传递到操作名称参数总是空。我该如何解决这个问题?

But the name parameter passed to the action is always null. How do I solve this?

推荐答案

在你的code ...你有2个不同的发布到服务器的方法:链接,表单按钮

In your code... you have 2 different ways of posting to the server: the link and the form button.

的问题是,所述的ActionLink没有办法让从输入客户端侧的值...只是原始值

The problem is that the ActionLink has no way to get the value from the input in client side... just the original value.

如果您preSS搜索按钮,你会看到一个值公布。

If you press the Search button, you will see a value posted.

现在,你可以使用一些jQuery来修改标准的ActionLink(不是Ajax.ActionLink): http://stackoverflow.com/a/1148468/7720

Now, you can use some jQuery to modify a standard ActionLink (not the Ajax.ActionLink): http://stackoverflow.com/a/1148468/7720

或...你可以改变,以做一个正常的一个Ajax的职位,而不是你的表格: http://stackoverflow.com/a/9051612/7720

Or... you can transform your Form in order to do a Ajax post instead of a normal one: http://stackoverflow.com/a/9051612/7720

阅读全文

相关推荐

最新文章