简体   繁体   English

将属性传递到控制器时,如何使用Html.BeginFrom方法?

[英]How do you use the Html.BeginFrom method when passing attributes to your controller?

First of all, I'm fairly certain that this is already answered, and I'm sorry that it's most likely a re-post, but I can't find the answer right now. 首先,我很确定这个问题已经解决了,很抱歉,它很可能是重新发布的,但是我现在找不到答案。 Zzz. Zzz。

Here is my razor code (stripped of non-essentials): 这是我的剃须刀代码(去除了不必要的内容):

@model SurveyApp.Models.LoginModel
@{
    var x = ViewBag.Culture; //x gets populated with "en-CA"
}
@using (Html.BeginForm("Login", "Account", FormMethod.Post, new { culture = x, id = "login-form" }))
{
    //...
    <a href="javascript:document.getElementById('login-form').submit()">Submit</a>
}

I'm pretty sure that this is all of the relevant code, because in my [httppost]login method, I am getting null in the second parameter. 我很确定这是所有相关的代码,因为在我的[httppost] login方法中,第二个参数中我为空。

Here is the login prototype (or whatever you call it): 这是登录原型(或您所说的任何名称):

public ActionResult Login(LoginModel model, string culture)
{
    //...
}

Am I using the attribute parameter of the Html.BeginForm call improperly? 我是否正确使用了Html.BeginForm调用的attribute参数?

You should put those as hidden form fields. 您应该将它们作为隐藏的表单字段。 The attributes on a form tag don't get submitted unless its the URL. 除非URL,否则不会提交form标记上的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM