Tag Archives: mvc

TeamCity 10 and ASP.NET MVC

I am new to team city and I read a book about it that describes how to build a java project using maven and use TeamCity to automate the build process.

But I am mainly .NET developer, so I started searching how to automate build and test of an ASP.NET MVC project.

The project was developed using Visual Studio 2015. First to consider when configuring TeamCity build step, is that you should have nuget installer as the first step. For that to work, you should already install nuget tools in TeamCity as below :


Then in build steps, configure nuget installer:


For the second step, you have to configure a Visual Studio runner type, so it would build the project:


But you may encounter an error while trying to build project, cause the teamcity server may not have proper MSIBUID tool, and libraries. So, according to the response in the stackoverflow, first you have to install the proper Build Tool  (you can find 2015 Version from https://www.microsoft.com/en-us/download/details.aspx?id=48159), and then copy the required web application folders for your targeted build.

It works, but if you have Unit test in your project, and it configured to use Visual Studio default Unit Test library, it may will fail cause it cant find appropriate dll.

In another post I will write about how to use NUnit and add it as build step in TeamCity.


ASP.NET MVC with models inheritance and views


Recently I bumped into a intersing question on stackoverflow.com. The problem was that user had a view but wanted to have some input elements based on variable model. I mean if model passed to view is a, render a Email text input and if it is b then render Name text input. But in mvc you can pass only one model to view. So I suggested have a base model and base view and by checking the type of model in view load the related view using partial as below:

 public ActionResult Base()
            return View(new DerviedOne());

 public class BaseModel
        public int Id { get; set; }

    public class DerviedOne : BaseModel
        public string Email { get; set; }

    public class DerviedTwo : BaseModel
        public string Name { get; set; }
 @using Models
@model Models.BaseModel

    ViewBag.Title = "Base";
    Layout = "~/Views/Shared/_Layout.cshtml";


@using (Html.BeginForm()) 

<div class="form-horizontal">


        @Html.ValidationSummary(true, "", new {@class = "text-danger"})

<div class="form-group">

<div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default"/>



    if(Model is DerviedOne)
         Html.RenderPartial("DerviedOneView", Model as DerviedOne);

    if (Model is DerviedTwo)
        Html.RenderPartial("DerviedTwoView", Model as DerviedTwo);