Instantly share code, notes, and snippets.

Embed
What would you like to do?
@model RandomPassword.Models.UserRegisterModel
@{
ViewData["Title"] = "Register";
}
<h2>Register</h2>
<h4>UserRegisterModel</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Register">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Username" class="control-label"></label>
<input asp-for="Username" class="form-control" />
<span asp-validation-for="Username" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Password" class="control-label"></label>
<input readonly="readonly" id="passwordInput" asp-for="Password" class="form-control" /> <!-- mark as readonly and add id -->
<button onclick="generatePassword()">Generate password</button> <!-- create button that triggers the generatePassword() function-->
<span asp-validation-for="Password" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
</div>
</div>
<script>
function generatePassword() {
event.preventDefault();
$.get(
"/Auth/GeneratePassword",
function (data) {
document.getElementById("passwordInput").value = data;
}
);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment