Reputation: 2200
I have an html form that uses HTTP.Post to talk to a method in the controller class. I don't have a specific view representing this method, just an HttpPost ActionResult without a relative cshtml view class. My code that calls this method is:
@using (Html.BeginForm("SaveCallout", "SaveCallout"))
{
<div class="editor-field">
@Html.DropDownListFor(m => m.ClientId, new SelectList(Model.Clients, "ClientId", "Name"))
@Html.ValidationMessageFor(model => model.ClientId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.Description, new { @id = "descriptionText" })
@Html.ValidationMessageFor(model => model.Description)
</div>
<input class="btn btn-primary btn-large" style="float: left; margin-right: 10px;" type="submit" value="Create Callout" />
<a class="btn btn-primary btn-large" href="@Url.Action("EmptyThisCallout", "Callout", null)" id="EmptyCart" style="float: left;">Clear Callout</a>
}
And my controller method is:
[HttpPost]
public ActionResult SaveCallout(CalloutViewModel viewModel)
{
var Callout = new Callout();
TryUpdateModel(Callout);
try
{
Callout.ClientId = viewModel.ClientId;
Callout.CalloutDate = DateTime.Now;
//Save invoice
proent.Callouts.Add(Callout);
proent.SaveChanges();
//Process the invoice
var tempCallout = CalloutLogic.GetCallout(this.HttpContext);
tempCallout.CreateCallout(Callout);
return RedirectToAction("Complete", new { id = Callout.CalloutId });
}
catch
{
//Invalid - redisplay with errors
return View(Callout);
}
}
This has worked flawlessly in a similar context before, but now I get the error message "The view 'SaveCallout' or its master was not found or no view engine supports the searched locations". I understand it is searching for a View but I have never needed one before for this process.
Can anyone see what I am doing wrong? Maybe I need to post more of my code?
Upvotes: 0
Views: 127
Reputation: 4189
The change you made is return View(Callout);
in catch
.
return View(...)
without providing a View name searches for a View that has the same name as your Action. You should put a View at Views -> SaveCallout -> SaveCallout.cshtml
if it was intentional, but I do not think it is.
I don't know what view you are making that HttpPost
from. Let it be called Foo
. If you want to return to Foo
view again, you should do:
catch(...)
{
return View("Foo", Callout);
}
Upvotes: 1