简体   繁体   中英

ASP.NET Server Control Type in PHP and ASP.NET MVC

I have created a server control in ASP.NET that generates DLL and we can use it an any another application we need. It is so helpful.

Now I want to create server control type of application in PHP and ASP.NET MVC 3. Can you provide me some sample application or example for PHP and ASP.NET MVC 3, so that I am able to achieve my task?

Dai's simple rules for converting from ASP.NET WebForms Controls to Anything Else:

  1. Extract the "model" from your control (ie encapsulate all of the possible input variables into a single object)
  2. Analyse how variations in this model object cause the rendered output (HTML) to change.
  3. Re-implement said rendered output-generation logic in your desired framework.

If I have this in WebForms:

public class WhateverControl : Control {
    public String SomeParameter { get; set; }
    public override void Render(HtmlTextWriter wtr) {
        wtr.WriteLine("<p>" + SomeParameter + "</p>");
    }
}

In PHP, like this:

class Model {
    // control parameters go here, e.g. visiblity, data to be displayed, form fields, etc
   public $someParameter;
}

public function renderWhatever(Model $model) {
    echo "<p>" . $model->someParameter . "</p>";
}

In ASP.NET MVC (using Helpers), like this:

public class Model {
    public String SomeParameter { get; set; }
}

public static MvcHtmlString Whatever(this HtmlHelper html, Model model) {
    return MvcHtmlString.Create("<p>" + model.SomeParameter + "</p>");
}

<%= html.Whatever( new Model() { SomeParameter = "arse" } ) %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM