Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts
0
Posted on 3:40 AM by Softminer and filed under ,

protected void Application_BeginRequest(object sender, EventArgs e)
{
	String fullOrigionalpath = Request.Url.ToString();

	if (fullOrigionalpath.Contains("?p="))
	{

		string website = "http://" + Request.Url.Authority;

		Response.Clear();
		//Response.StatusCode = 301;
		Response.Status = "301 Moved Permanently";
		//Response.Redirect(fullOrigionalpath.Replace("default.aspx?p=", "") + "/");
		Response.AddHeader("Location", website + "/" +  Request.QueryString["p"].ToString() + "/");
		Response.End();
	}
}
0
Posted on 2:02 AM by Softminer and filed under

public static void InfoButton(this HtmlHelper helper, string id, string description)
{
var response = helper.ViewContext.HttpContext.Response;
System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(helper, "_partial", 
new ViewDataDictionary { { "id", id }, { "descr", description } });
}
0
Posted on 1:16 AM by Softminer and filed under , ,

Sometime in ajax controller u wanna return back error message and Onfailure will be called only if status code is 500 and usually this error is handled by IIS, to skip this error do following:

Server.ClearError();
Response.StatusCode = 500;
Response.TrySkipIisCustomErrors = true;


+
1
Posted on 2:06 AM by Softminer and filed under ,

Definition from wikipedia

design pattern that prevents some duplicate form submissions, creating a more intuitive interface for user agents (users). PRG implements bookmarks and the refresh button in a predictable way that does not create duplicate form submissions.

Wikipedia

ASP.NET MVC - Using Post, Redirect, Get Pattern

ASP.NET MVC Tip #6 – Call RedirectToAction after Submitting a Form

PRG Pattern in the ASP.NET MVC Framework
0
Posted on 3:28 AM by Softminer and filed under

Problem with Resonse.Output in Razor

I have a helper class which writes directly in Response. I am using this helper class in my master page and it write in the position
where Helper class is called.

<% Html.MyHelper() %>

but in Razor

@{ Html.MyHelper() }

its writing the response on the begining of page.

A Razor view is rendered inside-out. Basically it writes content to temporary buffers which get written to the response stream when the top most layout page is reached.

private static void MyHelper(this HtmlHelper html)
{
HtmlTextWriter writer = new HtmlTextWriter(html.ViewContext.HttpContext.Response.Output);
}


to replace using
html.ViewContext.HttpContext.Response
with
html.ViewContext.write
0
0
Posted on 3:31 AM by Softminer and filed under ,

using Strongly Typed Html Helpers will map the model to the view and it will help to have compile time checking of the views.

in views instead of using
<%=Html.TextBox("username", Model.UserName)%>

you can use

<%= Html.TextBoxFor( m => m.UserName)%>

in controller:

public ActionResult LogOn(string userName, string password)

use

public ActionResult LogOn(LoginViewModel loginviewModel)

moreover you dont need to use ValueProvider["UserName"].AttemptedValue to access Html value and you can use model directly.

and for adding attribute
<%= Html.TextBoxFor(model => model.UserName , new { @calss="SingleTextBox" }) %>
0
Posted on 5:53 AM by Softminer and filed under ,

if you put this in .aspx code it will return back 0.0.0.0

  1.  <%= System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()%>

you have to fill in either in controller or in Helper class:

here is how to fill it in helper class:

http://www.craftyfella.com/2010/01/adding-assemblyversion-to-aspnet-mvc.html
0
Posted on 2:02 AM by Softminer and filed under


<img id="updating" src="/content/ajax-loader.gif" style="display: none;" alt="Updating ..." />

<br />
 <%= Ajax.ActionLink("Get Time", "GetTime",
 new AjaxOptions { UpdateTargetId = "time", LoadingElementId="updating" })%>


0
Posted on 12:43 AM by Softminer and filed under

Usually by default the Views in MVC are Inherited from Inherits="System.Web.Mvc.ViewPage but you can Inherit it from specific Model.


first you have to define your model in your MVC Model folder. but when I add this to Page


Inherits="System.Web.Mvc.ViewPage<MyProject.Models.MyModel>"  then I get the following Error :



Compiler Error Message: CS0426: The type name 'Models' does not exist in the type 'System.Web.UI.WebControls.Wizard'


Solution:


<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyModel>" %>


<%@ Import Namespace="MyProject.Models" %>