Need to change the user input right before going to the controller after form submit. The below solution changes the value but Modified input showing on the HTML Input field after replacing it from JavaScript.
Need alternative approach to change the value at Model level; therefore, the user cannot see the supplied input is changing.
<script>
$(document).ready(function () {
$("#submitButton").click(function (event) {
var element = document.getElementById("RawHtml");
var val = document.getElementById("RawHtml").value;
document.getElementById("RawHtml").value = val.replace(/</g, '<');
});
});
</script>
@using (Html.BeginForm())
{
<div class="field">
@Html.LabelFor(model => model.Name)
@Html.EditorFor(model => model.Name)
</div>
<div class="field">
@Html.LabelFor(model => model.RawHtml)
@Html.EditorFor(model => model.RawHtml)
</div>
<div>
<input name="Submit" type="submit" id="submitButton" />
</div>
}