Using javascript / jquery. I want to do this for every field that starts with
query.
queryForm['Foo'].value = queryForm['query.Foo'].value;
queryForm['Bar'].value = queryForm['query.Bar'].value;
queryForm['Baz'].value = queryForm['query.Baz'].value;
queryForm.submit();
And only if the queryForm['Foo'] exists.
Context: (You don't need to know this to answer my question, but it nice to know the context)
Above question is because of a fix / hack. Because I put the original Model in the ViewModel. Now Query is in the QueryViewModel.
@model QA.ViewModels.QueryViewModel
@using QA.ViewModels
@using QA.Enums
@{
var query = Model.Query;
}
<div class="form-group">
@Html.Required(model => query.Foo, "Describe the facts and circumstances that are relevant to the query", true, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-9">
@Html.EditorFor(model => query.Foo, new { htmlAttributes = new { @class = "form-control qa-tinymce-content" } })
@Html.ValidationMessageFor(model => query.Foo, "", new { @class = "text-danger" })
@Html.Hidden("Foo")
</div>
</div>