MVC3 partial view postback not work?

Up vote 1 down vote favorite share g+ share fb share tw.

I have LogOn partial view in the AccountController : public ActionResult LogOn() { return PartialView(); } // // POST: /Account/LogOn HttpPost public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState. IsValid) { if (ModelState. IsValid) { if (MembershipService.

ValidateUser(model. UserName, model. Password)) { FormsService.

SignIn(model. UserName, model. RememberMe); } else { ModelState.

AddModelError("", Resources.Account.Account. LoginFailureText); } } } return PartialView(model); } , I render this partial in my _Layout. Cshtml with: @{Html.

RenderAction("LogOn", "Account");} and the LogOn. Cshtml view is : @model Kalimat.Web.Models. LogOnModel @MvcHtmlString.

Create(Kalimat.Web.Resources.Account.Account. LoginTitle) @{ //Logined user view if (Request. IsAuthenticated) { @{@Kalimat.Web.Resources.Account.Account.

WelcomeText @Model. UserName! } @Kalimat.Web.Resources.Account.Account.

LoginStatusText @Kalimat.Web.Resources.Account.Account. ChangePswText } else { @Html. LabelFor(m => m.

UserName) @Html. TextBoxFor(m => m. UserName, new { @class = "inputfield" }) @Html.

ValidationMessageFor(m => m. UserName, "*") @Html. LabelFor(m => m.

Password) @Html. PasswordFor(m => m. Password, new { @class = "inputfield" }) @Html.

ValidationMessageFor(m => m. Password, "*") @Html. CheckBoxFor(m => m.

RememberMe) @Html. LabelFor(m => m. RememberMe) ****** @Html.

ValidationSummary(false, Kalimat.Web.Resources.Account.Account. LoginFailureText) @Kalimat.Web.Resources.Account.Account. NewAccountText @Kalimat.Web.Resources.Account.Account.

RecoverPswText } } when I run the application the LogOn view render correct but when clicking on the submit button nothing happens. Why? Asp.

Net-mvc-3 razor partialview link|improve this question asked Aug 4 '11 at 11:50Hala Aly477 90% accept rate.

First stop duplicating this line if (ModelState. IsValid) {} doesn't make sense ... as by looking to your code, you have submit button and everything but I think you missing @using(Ajax.BeginForm()) { //put all your html element in this // and also put submit button in it ... } here is the parameters for Ajax.BeginForm(): Ajax. BeginForm( string "ActionName", string "ControllerName", new routevalues {id="IDValue",message="MyMessage"}, new AjaxOptions {OnBegin=someFunction, OnFailure=failureFunction }, new { id = "FormName" } ) this is because you using ajax to post your action ...

Thanks for your answer but when using this solution the view first time displayed with the validation errors and when submit the view it not rendered to reflect that the user is logged until refreshing the page – Hala Aly Aug 4 '11 at 12:57 are you using Html. EnableClientValidation(); before ajax.beginform()? And in your action when you fulfilling all your checks like user is validated then you don't have to render the same html ... as you already used the form so create another div on the control that use same model but says user logged in or something and in this add UpdateTargetId attr: new AjaxOptions {UpdateTargetId = divid, OnBegin=someFunction, OnFailure=failureFunction } so when action is successfull it'll show this div instead of that ... but it's totally upto you how you manage your rendered html ... – Safran Ali Aug 4 '11 at 13:13 1 chk this out stackoverflow.com/questions/5733541/… – Safran Ali Aug 4 '11 at 13:15 Thanks, the validation is always displayed because I forget to add the style sheet – Hala Aly Aug 4 '11 at 7:22 Now I have another problem when main view perform HttpPost the application validate this partial view, how can I stop this behavior?

– Hala Aly Aug 4 '11 at 12:59.

You should be adding: @using(Html. BeginForm("Logon", "Account")) { // Submit form bits here } around your login bits to submit the information?

My fault for not noticing you were running a partial. It might be more suitable for your use? As for the Request.

IsAuthenticated think about it... you have submitted back to the page and the status would be false, just because you are calling the FormService halfway the process does not make the Request. IsAuthenticated change to true. I would set something in the Model or a ViewBag property to say that you are logged in.

– Luke Duddridge Aug 4 '11 at 13:04 thanks Luke, I use the ViewBag and now the application running – Hala Aly Aug 7 '11 at 7:23.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions