I guess, your alert box is an error view (which is also HTML formatted). I would say
(after looking in my glass sphere) your Model definition is not correct.
Your model reference:
@model SendAFaxWeb.Models.Home
looks very strange as well. Are you sure, your ViewModel is called "Home"?
And your Controller Action "GetHistory"
public ActionResult GetHistory()
{
return View(history)
}
what is its result? Your mentioned view? What for? To submit the form again? (... and again, and again, and again...)
I hope, (assuming your ViewModel name
is Home) you have:
[HttpGet]
public ActionResult GetHistory()
{
SendAFaxWeb.Models.Home history = new SendAFaxWeb.Models.Home();
history.Documents = GetDocuments();
return View(history)
}
[HttpPost]
public ActionResult GetHistory(SendAFaxWeb.Models.Home history)
{
return RedirectToAction("Index","Home")
}
If you need to update just a part of the View, it is better to use f. ex. jquery ajax function and update the html content.
Example:
The matching html element:
<div id="yourdivname">
</div>
The javascript / jquery function (assuming, the input text "myParamTextBox" has your parameter for query:
getUpdatedDivContent = function () {
var id = $("#myParamTextBox").val();
$.ajax({
url: '@Url.Action("UpdateMyDivContent", "Home")',
type: 'GET',
datatype: 'json',
traditional: true,
data: { myparameter: id },
error: function (data) {
alert($(data.responseText));
},
success: function (jsonresponse) {
$("#yourdivname").html(jsonresponse);
}
});
};
If you want to have a pretty nice formatted div content, you can return a partial view to the ajax function.
[HttpGet]
public ActionResult UpdateMyDivContent(string myparameter)
{
MyVeryNiceViewModel model = MyVeryNiceViewModel.Create(myparameter);
model.MyProperty1 = "What ever 1";
model.MyProperty2 = "What ever 2";
model.MyProperty3 = "What ever 3";
return PartialView("_yourUpdatedContent", model);
}
By the way: your form has an id="form". I'm not sure, if this is the happiest idea for an element name. It shouldn't however cause your issue here.