views:

55

answers:

2

Hello, I'm new in ASP.NET MVC so the question could appear 'stupid', sorry.

I have a Partial View inside my Home view.

The Partial View submit a form calling an Action Method inside the HomeController.

It works fine with server validation, the problem is that after the post only the Partial View is rendered.

How can I render the entire Home view after post?

Thanks

About the code:

Inside PartialView I have a form:

<% using (Html.BeginForm("Request", "Home")) { %>

Request is a ActionResult defined inside my HomeController.

[HttpPost]
public ActionResult Request(RequestModel model)
{
  if (ModelState.IsValid)
  {
    // Saving data .....
  }
  else
  {
     // Show Server Validation Errors
     return View();
  }
}

At this time, after the post, the ascx shows the server validation erros but only the PartialView ascx code is rendered. The Url looks like this after the post:

http://xxxxxxxxxxx/Home/Request

What I want is showing the entire Home view with the ascx inside showing server validation errors.

A: 

opaera - try changing the signature of your action perhaps to this:

[HttpPost]
public ActionResult Request(RequestModel model)
{
  if (ModelState.IsValid)
  {
    // you might also do a  return RedirectToAction("Details", newId);
    // where newId is the pk of the newly created object
    return PartialView();
  }
else
    // maybe you should return the new model here
    return PartialView(model);
}

cheers

jim
Sorry, not working. It renders just the ascx code.
opaera
ok - maybe investigate the RedirectToAction idea. also, i'm not sure what the entire purpose of the Request action is as there's no code for saving etc. maybe a fuller explanation might bring up better approaches to the problem. if you merely want to render the partial, then you shoudl look at the <%Html.RenderPartial()%> helper in place in your code??
jim
With RedirectToAction it doesn't show validation errors but makes a redirect. So it's not what I need. Thanks anyway.
opaera
it would be helpful to leave comments when downvoted as i've got no clue as to why the -1 feeling is so strong otherwise - tia
jim