Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从Html操作链接控件传递多个值,从用户输入的文本框捕获并发送到操作方法?_Javascript_Asp.net Mvc 4 - Fatal编程技术网

Javascript 如何从Html操作链接控件传递多个值,从用户输入的文本框捕获并发送到操作方法?

Javascript 如何从Html操作链接控件传递多个值,从用户输入的文本框捕获并发送到操作方法?,javascript,asp.net-mvc-4,Javascript,Asp.net Mvc 4,我有以下看法: <div class="form-group"> @Html.LabelFor(m => m.LoginId, new { @class = "col-md-2 control-label" }) <div class="col-md-10"> @Html.TextBoxFor(m => m.LoginId, new { @class = "form-control" }) @Html.Valid

我有以下看法:

<div class="form-group">
    @Html.LabelFor(m => m.LoginId, new { @class = "col-md-2 control-label" })
    <div class="col-md-10">
        @Html.TextBoxFor(m => m.LoginId, new { @class = "form-control" })
        @Html.ValidationMessageFor(m => m.LoginId, "", new { @class = "text-danger" })
    </div>
</div>
<div class="form-group">
    @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
    <div class="col-md-10">
        @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
        @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
    </div>
</div>
<div class="form-group">
    <div class="col-md-offset-2 col-md-10">            
        @Html.ActionLink("Log in", "Login1", null, new { @class = "link" })
    </div>
</div>
这是控制器动作方法:

public ActionResult Login1(string loginid,string password)
{
    if (loginid == null)
    {
        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
    }
    User user = db.Users.Find(loginid);
    if (user == null)
    {
        return HttpNotFound();
    }
    return RedirectToAction("Index", "Products");
}
我已输入loginid=a和password=b。 但问题是:它正在发送loginid=:a?password=b和password=null。
如何正确发送参数?

点击“提交”按钮,表单将自动发布,您无需编写任何其他代码


请确保您的文本框名称(而不是ID)与操作中的参数名称匹配。

我认为错误在ajax函数中,但我不是专家。“?”是问题的根源。目前的情况如下:

this.href = this.href + '?loginid=' + encodeURIComponent(loginid);
this.href = this.href + '?password=' + encodeURIComponent(pass); 
但应该是:

this.href = this.href + '?loginid=' + encodeURIComponent(loginid);
this.href = this.href + '&password=' + encodeURIComponent(pass); 

第二个需要是
&密码=
(不是
)。但是你真的把密码作为url参数传递了吗。建议你重新考虑这一点,并使用一个表格。完美!是的,我肯定会改进。有什么建议吗,先生?将您的链接更改为提交按钮,然后发布到
[HttpPost]公共操作结果登录(XXX模型)
方法(其中
XXX
是您在视图中使用的模型)。不知何故,我认为您的用户不会因为您公开了他们的密码而太高兴:)
this.href = this.href + '?loginid=' + encodeURIComponent(loginid);
this.href = this.href + '&password=' + encodeURIComponent(pass);