Giter Site home page Giter Site logo

omar-salem / stronglytypedviews Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 4.85 MB

Avoid runtime errors by using View helpers strongly bound to your models

Home Page: https://www.nuget.org/packages/StronglyTypedViews/

C# 4.11% CSS 1.13% ASP 0.02% JavaScript 80.64% PowerShell 14.10%

stronglytypedviews's Introduction

StronglyTypedViews

Avoid runtime error "The model item passed into the dictionary is of type ‘X’ but this dictionary requires a model item of type ‘Y‘".

e.g instead of:

public ViewResult GetProduct(int id)
{
    return View("GetProduct", id);
}

with StronglyTypedViews you can write

    public ViewResult GetProduct(int id)
    {
        return MVCStronglyTypedViews.Areas.Administration.Management.GetProduct(id);
    }

The template generates truly strongly typed views to use in your controllers with zero configuration.

Only C# is supported for now.

The template discovers referenced namespaces in .cshtml files, base types (int, bool, String, etc..) and user made classes will work without configuration.

If the template gives build errors due to undiscovered namespaces,either:

-Write the fully qualified name of the model to the view(i.e: @model System.Text.StringBuilder)

or

-Add the required namespace to the view:

@using System.Text;

Input

-Areas -Administration -Views -Management -GetProduct.cshtml

@model int
<p>@Model</p>

How to use

1-Run template 2-Build Project

In controllers:

    public ViewResult GetProduct(int id)
    {
        return MVCStronglyTypedViews.Areas.Administration.Management.GetProduct(id);
    }

to return as Partial View:

	public virtual PartialViewResult Edit(int id)
    {
        var viewResult = MVCStronglyTypedViews.Areas.Administration.Management.GetProduct(id);
        return MVCStronglyTypedViews.ControllerExtensions.PartialView(viewResult);
    }

In views:

    @{
		Html.RenderPartial(MVCStronglyTypedViews.Areas.Administration.Management.GetProduct(90)); 
     }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.