我试图将数据从视图传递到我的.net应用程序中的控制器。我希望尽可能多地保留原始的html语法,因为它和相应的css是从adobe muse导入的。我创建了以下模型,我试图填写:
public class LoginModel
{
public string Email { get; set;}
public string Password { get; set; }
}
我试图通过以下方法检索输入:
[HttpPost]
public IActionResult LoginBody(LoginModel info)
{
System.Diagnostics.Debug.WriteLine(email);
System.Diagnostics.Debug.WriteLine(password);
return View();
}
我的HTML是:
<form class="form-grp clearfix grpelem" id="widgetu732" method="post" enctype="multipart/form-data" action="">
<div class="clearfix grpelem" id="u733-4">
</div>
<div class="clearfix grpelem" id="u734-4">
</div>
<div class="clearfix grpelem" id="u743-4">
</div>
<button class="submit-btn NoWrap clearfix grpelem" id="u744-3" type="submit" value=" " tabindex="3">
<div style="margin-top:-13px;height:13px;">
<p> </p>
</div>
</button>
<div class="fld-grp clearfix grpelem" id="widgetu749" data-required="true">
<label class="fld-label actAsDiv clearfix grpelem" id="u752-4" for="widgetu749_input"><!-- content --><span class="actAsPara">PASSWORD:</span></label>
<span class="fld-input NoWrap actAsDiv clearfix grpelem" id="u750-4" placeholder="PASSWORD"><!-- content --><input class="wrapped-input" type="text" id="widgetu749_input" name="Password" tabindex="2" /></span>
</div>
<div class="fld-grp clearfix grpelem" id="widgetu735" data-required="true">
<label class="fld-label actAsDiv clearfix grpelem" id="u738-4" for="widgetu735_input"><!-- content --><span class="actAsPara">EMAIL:</span></label>
<span class="fld-input NoWrap actAsDiv clearfix grpelem" id="u737-4" placeholder="EMAIL"><!-- content --><input class="wrapped-input" type="text" id="widgetu735_input" name="Email" tabindex="1" /></span>
</div>
</form>
我该如何修改我的html以便能够接收输入?
您需要更改输入字段的名称
<div class="fld-grp clearfix grpelem" id="widgetu749" data-required="true">
<label class="fld-label actAsDiv clearfix grpelem" id="u752-4" for="widgetu749_input"><!-- content --><span class="actAsPara">PASSWORD:</span></label>
<span class="fld-input NoWrap actAsDiv clearfix grpelem" id="u750-4" placeholder="PASSWORD"><!-- content --><input class="wrapped-input" type="text" id="widgetu749_input" name="Password" tabindex="2" /></span>
</div>
<div class="fld-grp clearfix grpelem" id="widgetu735" data-required="true">
<label class="fld-label actAsDiv clearfix grpelem" id="u738-4" for="widgetu735_input"><!-- content --><span class="actAsPara">EMAIL:</span></label>
<span class="fld-input NoWrap actAsDiv clearfix grpelem" id="u737-4" placeholder="EMAIL"><!-- content --><input class="wrapped-input" type="text" id="widgetu735_input" name="Email" tabindex="1" /></span>
</div>
Console.Write在ASP.NET中不起作用,因为它是使用浏览器调用的。您可以使用Debug.Writeline
See Stack Overflow question Where does Console.WriteLine go in ASP.NET?
此外,为了访问表单数据
[HttpPost]
public IActionResult LoginBody(LoginModel info)
{
Debug.WriteLine(info.Email);
Debug.WriteLine(info.Password);
return View();
}
注意:Debug.WriteLine仅在调试期间有效。
您可以使用
[HttpPost]
public IActionResult LoginBody()
{
string email = Request["custom_U735"];
string password = Request["custom_U749"];
return View();
}