将文本框值从View传递给操作,而不使用Html.begin表单和Submit按钮 [英] Passing textbox value from View to action without using Html.begin form and Submit button

查看:109
本文介绍了将文本框值从View传递给操作,而不使用Html.begin表单和Submit按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个texbox。当用户在文本框中输入一些输入并单击下面的actionlink时,文本框的值将传递给控制器​​中的actionResult(FWMenu)。我不能在视图中使用html.begin表单和提交按钮。我甚至无法在我的控制器中使用[httppost]。这样可能吗?如果是,那么请帮助我。我没有在模型中使用任何课程。



以下是我的操作员。



I have created a texbox. When user give some input in the textbox and click the actionlink below, the value of the textbox will get pass to the actionResult(FWMenu) in the controller. I can not use html.begin form and submit button in the view. And i can not even use [httppost] in my controller. Is it possible in that way? If yes then please help me how. I have not used any class in model.

Below is my Controller.

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult FWMenu(string username)
        {
            return View();
        }

    }





这是我的观点。





This is my View.

<div>
    @Html.TextBox("txtUserName")
    @Html.ActionLink("Login", "FWMenu", new { username = @Html.TextBox("txtUserName") })
</div>

推荐答案

Google从jquery调用mvc动作,你会发现很多例子。只要确保你有类型:GET而不是输入:POST



http://stackoverflow.com/questions/4120212/mvc-ajax-json-post-to-controller-action-method [< a href =http://stackoverflow.com/questions/4120212/mvc-ajax-json-post-to-controller-action-methodtarget =_ blanktitle =New Window> ^ ]



您需要触发通话的内容,因此要么使用按钮或链接的点击事件,要么使用文本框的模糊事件(如果您需要)当用户标签离开时发出呼叫。谷歌jquery模糊事件输入框,如果你不知道如何将代码附加到元素事件。



为了抢先你的下一个问题,没有我赢了'为你写代码。
Google "call mvc action from jquery" and you'll find lots of examples. Just make sure you have type:"GET" rather than type:"POST"

http://stackoverflow.com/questions/4120212/mvc-ajax-json-post-to-controller-action-method[^]

You'll need something to trigger your call, so either use a click event of a button or link, or use the blur event of the textbox if you want the call to be made when the user tabs away. google "jquery blur event input box" if you don't know how to attach code to element events.

To pre-empt your next question, no I won't write the code for you.


这篇关于将文本框值从View传递给操作,而不使用Html.begin表单和Submit按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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