我遇到这种情况:
@using (Html.BeginForm("CreateNewApplication", "Token", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<label for="app-name" class="op-form op-label">Application:</label>
@Html.TextBoxFor(a => a.appName, new { @placeholder = "Nome dell'applicazione", @class = "op-form op-text app-name" })<br />
<label for="token" class="op-form op-label">Token:</label>
<button id="generate-token" class="op-form" value="Genera Token">Generate Token</button>
@Html.TextBoxFor(a => a.appToken, new { @placeholder = "Token", @id = "token", @class = "op -form op-text token" })<br />
<input id="submit" type="submit" class="op-form op-submit" value="Submit" />
}
按钮调用此Javascript函数:
$('#generate-token').click(function () {
var token = Math.random().toString(36).slice(2);
$("#token").val(token);
});
问题是当单击按钮时,Javascript函数被正确调用,但在我的Token控制器中也称为CreateNewToken方法。虽然我只想在点击按钮上调用Javascript并在点击提交时调用方法控制器。 有可能吗?怎么样?
答案 0 :(得分:0)