0

I am newbie in ASP.NET MVC. I have a below requirement.

I need to show dynamically pie charts on the Dashboard page. I will decide total count of pie charts at run time. So, I have created a Partial View of the pie chart and a model class.

First, I will hit the database and fill data into model class. I din'd find any tutorial.

Controller Code :

public ActionResult _Dashboard()
    {
        try
        {
            _dashboard = new Dashboard();
            var model = _dashboard.GetToolsUtilization();
            return View(model);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        { }

    }

Tools class

public class Tools
{
    public string toolName { get; set; }
    public int used { get; set; }
    public int free { get; set; }
}

_Dashboard.cshtml Page

<div class="col-lg-12">



    @foreach (var item in Model)
    {
        <div class="dash-unit col-lg-3">
            Html.Partial("~/Views/Shared/toolGaugeInfo.cshtml", item)
        </div>

    }

    </div>

ToolGauageInfo.cshtml

@model NETMS.DAL.ToolGauageInfo

I think, Partial view page is fine. I will call controller on page load by ajax call. Now, I don't know how to return model from controller.

1

1 Answer 1

0

You will calculate number of pie charts and save it in a List<PieChartModel> or somrthing and you can create View that take @model List<PieChartModel> and loop over list to display your partialview

@foreach(var pie in Model)
{
   Html.Partial("_PieView", pie);
}
Sign up to request clarification or add additional context in comments.

3 Comments

No, sorry. I tried but I wasn't able to achieve it.
@Mohit what do you mean by achieve it ?? What is the error ?
Share your code with more details including the partial view you implement and controller and your exact problem as now I don't understand you

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.