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()
{
??
}