Category Archives: Principle

:-) Thank you

For those who want to get a analysis tools for dentist

http://blog.koumei.net/2009/11/11/lab-analysis-utility-for-dentist-schwartz-korkhaus-model/

Thank you for showing your interest of this gadget.

I didn’t notice that there so many demands on this gadget. Instead of sending request in the blog, please send me email. My email is at the bottom of my blog.

Thanks.

bing! site wide search plug-in for wordpress

It’s somehow a little bit useful to have bing search engine integrate to your website. I just create a plug-in for wordpress regarding this. This plug-in is designed to be a right panel widget. If you need, just download the ZIP file and upload to your wordpress plug-in, activate it, then you can arrange the widget on your right panel.

You can also define the title for this plug-in: you need to setup the search site, if you don’t, then will be the current site. Please note that “http://” is not needed as shown below:

On the right panel, you can see the bing site search widget is activated:

And when you type in the search bar with your keyword,  you will see the search result:

Simple and easy, just go to open source section: http://blog.koumei.net/open-source/#bing

ASP.NET MVC Whole Site 301 Permanent Redirect

For some reasons, we need to permanently redirect the whole website to another website. It would be much easier that you are the owner of the server. But most of time you just host your website on the server out there. It wouldn’t be a big problem that your hosting company will support you to do some simple 301 redirect or may you have enough privilege to do it yourself. Is it possible to redirect permanently the website to other website by programming a little bit?

Sure you can. With MVC routing facilities, you can define your customized redirect logic: CREATE AN EMPTY MVC PROJECT, MODIFY GLOBAL.ASPX.CS FILE ONLY ON THIS EXAMPLE:

First of all, define two objects which implemented IRouteHandler and IHttpHandler, you can feel free to define those two objects on Global.aspx.cs file:

//@Implements IRouteHandler
class RedirectRouteHandler : IRouteHandler
{
private string newUrl;
public RedirectRouteHandler(string newUrl) { this.newUrl = newUrl; }
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new RedirectHandler(newUrl);
}
}

//@object implements IHttpHandler
class RedirectHandler : IHttpHandler
{
private string newUrl;

public RedirectHandler(string newUrl) { this.newUrl = newUrl; }

public bool IsReusable { get { return true; } }

public void ProcessRequest(HttpContext httpContext)
{
httpContext.Response.Status = “301 Moved Permanently”;
httpContext.Response.StatusCode = 301;
httpContext.Response.AppendHeader(“Location”, newUrl);
return;
}
}

Then add one line on RegisterRoutes(RouteCollection routes) method (in Global.aspx.cs):

routes.Add(new Route(“{*pathInfo}”, new RedirectRouteHandler(@”http://koumei.net”));

Now all request to the website will redirect to “koumei.net” permanently. :)

An Experimental Html5 Drama

After reading through all useful articles about Html5 and CSS3, I try to create a new Html5 template for my blog. If you would like to see something new about html5 and css3, have a look at this article:
70 Must-Have CSS3 and HTML5 Tutorials and Resources

Koumei’s experimental page is available here: http://koumei.net/html5.html

Nothing much currently. I am quite interested in creating the gradient background and rounded corner.

This page will be kept updating.

Say Hello to koumei.net on HelloVPS

Yesterday koumei.net was condemned due to bring down the whole hosting server for harmful scripts, according to the server support. Not easy to contact them since they are in states. I am desperate to stay on their server without any secure. I would rather move to another server than to explain I am innocent. So I will move out from their server, I don’t like their service as well. How come they close down my website so suddenly without 1 day or 2 days notice?

Thanks to Howie from states who provides me a shelter at this moment. koumei.net is homeless, desperate and depressed last night, but because of his kindly help that make me home again. Now let us say hello to koumei.net again on HelloVPS (HelloVPS.com).

hellovps

hellovps

MVC2 Bug on Data Binding in Listbox?

Seems MVC and MVC 2 don’t realize that there is an issue when binding the data on the view:

Given an extension on HtmlHelper: this extension will generate a list box in view based on the collection “cakes”. (Because I like cake, so I use dessert object as example :)

public static MvcHtmlString MyDropDownList(this HtmlHelper target, string controlName, IQueryable<Cake> cakes, object htmlAttr)
{
if (cakes== null)
return MvcHtmlString.Empty;
var cakesList = new SelectList(cakes, “Id”, “CakesName”);
return target.ListBox(controlName, cakesList, htmlAttr);
}

It is okay, but the main issue is if the when I specify the Model data on control name, it IS SUPPOSED to generate the list box with the data which retrieved from database are selected. Yes.  IT IS SUPPOSED TO BE. But, unfortunately, MVC fail to automatically bind data for us…  The data “cakesList” is showing properly, but with no preselect options. In most of the business logic, it’s not gonna work, because it is no point for user to re-select the options every time before save the data.

In this case, MVC is not gonna auto-bind the data for us, we just need to figure out another way to display and manipulate the data properly. So we will change something on the extension, view and the controller:

1. On the view, don’t specify the name to model’s name, For example, the data which will be weaved to list box is CakeViewData.CakeList, the data related to database is CakeViewData.Dessert.Cakes. Normally, we will use the extension to weave the data:

<%=Html.MyDropDownList(“Dessert.Cakes”, Model.CakeList, new { @class = “multiselect”, size = 5 })%>

Since MVC is not gonna take care of the data binding, The name (on parameter controlName) should and NEED to use other name instead. Change “Cakes” to any other name, for example, change to “MyCakes”:

<%=Html.MyDropDownList(“Dessert.MyCakes”, Model.CakeList, new { @class = “multiselect”, size = 5 })%>

2. Extension is changed to:

public static MvcHtmlString MyListBoxWithSelectedList(this HtmlHelper target, string name, IQueryable<Cake> cakes, List<string> selected, object htmlAttr)
{
if (interests == null)
return MvcHtmlString.Empty;
var cakeList = new MultiSelectList(cakes, “Id”, “CakeName”, selected);
return target.ListBox(name, cakeList, htmlAttr);
}

I just add a parameter “List<string> selected” in the extension which will be used in MultiSelectList object that can be bind to the the items to be selected.

3. In controller, before saving the data, need to use FormCollection or Request["Dessert.MyCakes"] to obtain the data “MyCakes” manually.

string myCakes = Request["Dessert.MyCakes"];
Dessert dessert = new Dessert{Cake = myCakes};

It might not be a bug actually. And in this example you can feel how flexibility that MVC can bring you: the way to manipulate the model or data varies!  :)

Happy programming in MVC 2!