There is no "postback" in ASP.NET MVC; it's a different paradigm from WebForms.
Take a look at the written movie database tutorial;
do not just read it, actually do it.
You will see how it handles POST ... do not confuse POST with "Postback".
You can help others help you by showing more of your code.
Regards,
Gerry (Lowry)
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
And if you throw an exception somewhere so that the code falls through and uses the return View("Error") at the bottom, does the save file dialog pop up? Are there partial views beign returned? Have you tried naming the methods differently? (since both are
called LogOn). Have you tried decorating the normal LogOn method with [AcceptVerbs(HttpVerbs.Get)] and checked if that might make a difference?
Just spawning ideas to try since I'm not seeing anything out of the ordinary on first sight.
Wishing coding was like Scottish weather: Don't like it? Wait for 5 minutes.
IvanL, .NET Developer
I test and can not find why!, my project work previous week and there is no error or savefile dialog in same action and controller, But i can not find why this problem accour!!!!!
Could you try naming the functions differently? Like Index() and IndexPost(). And use a return View("Index"); in the later. It's strange that your solution started malfuntioning in the middle of development. Did you make any significant changes or override
certain standard MVC behaviour somewhere?
Wishing coding was like Scottish weather: Don't like it? Wait for 5 minutes.
IvanL, .NET Developer
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
mahdiit
Member
5 Points
8 Posts
[Problem] Asp.net MVC Postback always show savefile dialog!
May 02, 2010 03:59 PM|LINK
I am using asp.net mvc,
I have a problem that i can not resolve it, when i return a view() in form postback, Browser show savefile dialog.
I save file and open it, It contian all page html content.
I also try to set content type by set response.contenttype but there is no effect on result.
Firefox say content type is application/json,
post method like this simple code : public actionresult index(){ return view() }
Can you help me?
gerrylowry
All-Star
20525 Points
5713 Posts
Re: [Problem] Asp.net MVC Postback always show savefile dialog!
May 02, 2010 07:00 PM|LINK
There is no "postback" in ASP.NET MVC; it's a different paradigm from WebForms.
Take a look at the written movie database tutorial;
do not just read it, actually do it.
You will see how it handles POST ... do not confuse POST with "Postback".
You can help others help you by showing more of your code.
Regards,
Gerry (Lowry)
gerrylowry
All-Star
20525 Points
5713 Posts
Re: [Problem] Asp.net MVC Postback always show savefile dialog!
May 02, 2010 07:05 PM|LINK
P.S.: movie database tutorial is here:
http://www.asp.net/learn/mvc/tutorial-21-cs.aspx c#
http://www.asp.net/learn/mvc/tutorial-21-vb.aspx vb
IvanLieckens
Participant
1189 Points
194 Posts
Re: [Problem] Asp.net MVC Postback always show savefile dialog!
May 02, 2010 09:25 PM|LINK
Could you post your controller and view code? Are you using AJAX?
IvanL, .NET Developer
mahdiit
Member
5 Points
8 Posts
Re: [Problem] Asp.net MVC Postback always show savefile dialog!
May 03, 2010 04:48 AM|LINK
// // GET: /LogOn/ public ActionResult LogOn() { string CaptchaImageString = Common.Captcha.DPMSCaptchaImage.RandomCode(DPMS.Common.Captcha.CaptchaType.Numeric, 3); Session["Captcha"] = CaptchaImageString; return View(); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult LogOn(FormCollection FormData) { try { BLL.BLLResult res = new DPMS.BLL.BLLResult(); if (Session["Captcha"].Equals(FormData["Captcha"])) { BLL.User user = new DPMS.BLL.User(); res = user.Find(FormData["UserName"], FormData["UserPassword"], FormData["Captcha"], FormData["PKI_thumbprint"], FormData["PKI_sing"]); DAL.TbUser usr = (DAL.TbUser)res.Model; if (res.IsSuccess) { //Save success Login Log HttpBrowserCapabilitiesBase browser = Request.Browser; string strBrwoser = browser.Browser + " " + browser.Version; if (browser.EcmaScriptVersion == null || browser.EcmaScriptVersion.Major < 1) strBrwoser += ";NO JAVASCRIPT"; if (browser.Beta) strBrwoser += ";Beta"; if (!browser.Cookies) strBrwoser += ";No Cookies"; if (!browser.Frames) strBrwoser += ";No Frame Support"; if (browser.IsMobileDevice) strBrwoser += ";Mobile Browser"; string LogContent = "<?xml version='1.0' encoding='windows-1256'?><Login><UserName>" + FormData["UserName"] + "</UserName><UserPassword>" + FormData["UserPassword"] + "</UserPassword><Captcha>" + FormData["Captcha"] + "</Captcha><PKI_thumbprint>" + FormData["PKI_thumbprint"] + "</PKI_thumbprint><PKI_sing>" + FormData["PKI_sing"] + "</PKI_sing></Login>"; string LogClientIP = Request.UserHostAddress; string LogServerDomain = Request.Url.Host.ToString(); string LogCertificate = FormData["PKI_thumbprint"]; string LogSign = FormData["PKI_sing"]; string LogBrowser = strBrwoser; string UserId = usr.UserId.ToString(); string ResourceId = Request.Path; string LogType = LogTools.LogType.Login.ToString(); LogTools.dbLog(LogContent, LogClientIP, LogServerDomain, LogCertificate, LogSign, LogBrowser, UserId, ResourceId, LogType); //end Save Log Session["UserId"] = usr.UserId; Session["PersonName"] = usr.TbPerson.PersonName; Session["PersonLastName"] = usr.TbPerson.PersonLastName; usr.TbDistributionPointReference.Load(); if (usr.TbDistributionPoint != null) { Session["DestributionPointId"] = usr.TbDistributionPoint.DistributionPointId; Session["DistributionPointName"] = usr.TbDistributionPoint.DistributionPointName; Session["XmlDocCount"] = user.XmlDocCount(usr.UserId); } else { Session["DestributionPointId"] = ""; Session["DistributionPointName"] = ""; } usr.TbSherkatReference.Load(); if (usr.TbSherkat != null) { Session["SherkatId"] = usr.TbSherkat.SherkatID; Session["SherkatName"] = usr.TbSherkat.SherkatName; } else Session["SherkatId"] = ""; if (usr.TbPerson.PersonGender == true) Session["PersonGender"] = 1; else if (usr.TbPerson.PersonGender == false) Session["PersonGender"] = 0; else if (usr.TbPerson.PersonGender == null) Session["PersonGender"] = 2; if (usr.UserLastLoginDatetime != null) Session["UserLastLoginDatetime"] = usr.UserLastLoginDatetime; else Session["UserLastLoginDatetime"] = ""; Session["MsgCount"] = user.MsgCount(usr.UserId); Session["XmlDocCount"] = user.XmlDocCount(usr.UserId); FormsAuthentication.RedirectFromLoginPage(FormData["UserName"], false); ViewData["UserName"] = FormData["UserName"]; user.InserLastLoginDatetime(usr.UserId); } else { //Save badLogin Log HttpBrowserCapabilitiesBase browser = Request.Browser; string strBrwoser = browser.Browser + " " + browser.Version; if (browser.EcmaScriptVersion == null || browser.EcmaScriptVersion.Major < 1) strBrwoser += ";NO JAVASCRIPT"; if (browser.Beta) strBrwoser += ";Beta"; if (!browser.Cookies) strBrwoser += ";No Cookies"; if (!browser.Frames) strBrwoser += ";No Frame Support"; if (browser.IsMobileDevice) strBrwoser += ";Mobile Browser"; string LogContent = "<?xml version='1.0' encoding='windows-1256'?><Login><UserName>" + FormData["UserName"] + "</UserName><UserPassword>" + FormData["UserPassword"] + "</UserPassword><Captcha>" + FormData["Captcha"] + "</Captcha><PKI_thumbprint>" + FormData["PKI_thumbprint"] + "</PKI_thumbprint><PKI_sing>" + FormData["PKI_sing"] + "</PKI_sing></Login>"; string LogClientIP = Request.UserHostAddress; string LogServerDomain = Request.Url.Host.ToString(); string LogCertificate = FormData["PKI_thumbprint"]; string LogSign = FormData["PKI_sing"]; string LogBrowser = strBrwoser; string UserId = "" ; if (usr != null ) UserId = usr.UserId.ToString(); string ResourceId = Request.Path; string LogType = LogTools.LogType.badLogin.ToString(); LogTools.dbLog(LogContent, LogClientIP, LogServerDomain, LogCertificate, LogSign, LogBrowser, UserId, ResourceId, LogType); //end Save Log } } else { res.FieldErrorList.Add("لطفا کد امنیتی درست وارد کنید", "Captcha"); } ViewData["error"] = res.ErrorMessage; this.AddRuleViolations(res.FieldErrorList); return View(); } catch (Exception ex) { LogTools.Logger.DebugException("Logon", ex); if (ex.InnerException != null) { LogTools.Logger.DebugException("Logon", ex.InnerException); } } return View("Error"); }Error Accour in this line:
this.AddRuleViolations(res.FieldErrorList); return View();When this view return browser show save dialog page.
mahdiit
Member
5 Points
8 Posts
Re: [Problem] Asp.net MVC Postback always show savefile dialog!
May 03, 2010 05:54 AM|LINK
IvanLieckens
Participant
1189 Points
194 Posts
Re: [Problem] Asp.net MVC Postback always show savefile dialog!
May 03, 2010 09:06 AM|LINK
And if you throw an exception somewhere so that the code falls through and uses the return View("Error") at the bottom, does the save file dialog pop up? Are there partial views beign returned? Have you tried naming the methods differently? (since both are called LogOn). Have you tried decorating the normal LogOn method with [AcceptVerbs(HttpVerbs.Get)] and checked if that might make a difference?
Just spawning ideas to try since I'm not seeing anything out of the ordinary on first sight.
IvanL, .NET Developer
mahdiit
Member
5 Points
8 Posts
Re: [Problem] Asp.net MVC Postback always show savefile dialog!
May 03, 2010 09:51 AM|LINK
i try creating a simple post method, but this code also show savedialog file, I can say all return view in my post in project show save dialog file,
namespace RaahbarMVC.UI.Controllers { public class TestController : Controller { public ActionResult Index() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(FormCollection FormData) { return View(); } } }<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MainSite.Master" Inherits="System.Web.Mvc.ViewPage" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Index </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Index</h2> <form method="post"> <%=UIControls.CheckBox("test") %> <p><input type="submit" value="ادامه" /></p> </form> </asp:Content>I test and can not find why!, my project work previous week and there is no error or savefile dialog in same action and controller, But i can not find why this problem accour!!!!!
IvanLieckens
Participant
1189 Points
194 Posts
Re: [Problem] Asp.net MVC Postback always show savefile dialog!
May 03, 2010 12:58 PM|LINK
Could you try naming the functions differently? Like Index() and IndexPost(). And use a return View("Index"); in the later. It's strange that your solution started malfuntioning in the middle of development. Did you make any significant changes or override certain standard MVC behaviour somewhere?
IvanL, .NET Developer
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: [Problem] Asp.net MVC Postback always show savefile dialog!
May 04, 2010 03:25 AM|LINK
The only reason the Save File Dialog is shown is due to Content Type.
I think you have set Response.ContentType in some where in Http Module or global.asax.
just try this code,
Not Show Dialog
Response.ContentType = "text/html";
Response.Clear();
Response.Write("A");
Response.End();
Shows Dialog
Response.ContentType = "application/octet-stream";
Response.Clear();
Response.Write("A");
Response.End();
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD