我的 HttpPost 需要一些帮助。我不知道在 HttpPost 上写什么才能在我的视图中使用我的工作代码
我写了一个代码来生成密码:
private static string PasswordGenerator(int passwordLength, bool strongPassword)
{
int seed = Random.Next(1, int.MaxValue);
//const string allowedChars = "ABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
const string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
const string specialCharacters = @"!#$%&'()*+,-./:;<=>?@[\]_";
var chars = new char[passwordLength];
var rd = new Random(seed);
for (var i = 0 ; i < passwordLength; i++)
{
// If we are to use special characters
if (strongPassword && i % Random.Next(3, passwordLength) == 0 )
{
chars[i] = specialCharacters[rd.Next(0 , specialCharacters.Length)];
}
else
{
chars[i] = allowedChars[rd.Next(0 , allowedChars.Length)];
}
}
return new string(chars);
}
现在我也有一个看法:
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm("Index", "PasswordGenerator", FormMethod.Post))
{
<table class="passwordViewTable">
<tr>
<td>Password Length:</td>
<td class="rechterKolom"> <input type="text" value="8" id="length_field"> (4 - 64 chars)</td>
</tr>
<tr>
<td>Include Letters:</td>
<td><input type="checkbox" id="checkbox_letters" checked> ( e.g. abcdef) <br /></td>
</tr>
<tr>
<td>Quantity:</td>
<td>
<select id="dropdown_quantity" class="styled">
<option value="1">1</option>
<option value="2">2</option>
</select> <br />
</td>
</tr>
<tr>
<td><button type="submit" id="btn_submit">Submit</button> </td>
</tr>
</table>
}
现在我不知道在 httpPost 函数上写什么来让代码在视图上工作
[HttpGet]
public ActionResult Generate()
{
return View("Index");
}
[HttpPost]
public ActionResult PasswordGenerator()
{
??
}