ActionLink的提交型号值 [英] ActionLink to submit Model value

查看:99
本文介绍了ActionLink的提交型号值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的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

这篇关于ActionLink的提交型号值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆