0

I am evaluating TypeScript to see if it could save time in development for my requirements. Lets say I define simple classes to get and set hidden fields with the main purpose of being generic and working with MVC models.

class BaseObject {
    _Name: string;
    constructor(public name) { this._Name = name; }
}

interface BaseForm {
    SaveFields(): void;
    GetFields(): void;
    ToQueryString(): string;
    ToJsonString(): string;
}


class BaseReportForm extends BaseObject implements BaseForm {

    constructor(name) { super(name); }

    public PageNumber: number;
    public AllowPaging: bool;
    public ExportLink: string;
    ...
    SaveFields() {//WRITE HIDDEN FIELDS TO FORM }
    GetFields() { //GET HIDDEN FIELDS FROM FORM}
    ToQueryString() { return "Hidden Fields To Query String"; }
    ToJsonString() { return "Hidden Fields To Json"; }
} 

This all works great, however, I am not seeing anything that would allow me to work with @Models. It would be nice to be able to have the ability to magically do the following:

var ReportForm=new ReportForm(@Model.Report);

I am aware that to achieve this functionality there would have to be another translation layer of translations. Are there any tools that would help if it turns out to be a time saver? Similar to an ORM mapper or auto mapper but would work with JS or TypeScript?

1 Answer 1

1

Yup there is TypeLITE that will convert your C# classes to TypeScript : http://type.litesolutions.net/

First create a TypeScript class from your C# class using TypeLITE. Next pass in your c# class instance to your TypeScript in your razor view as JSON https://stackoverflow.com/a/4072787/390330

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.