Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have the below procedure:
HTML
Create PROCEDURE Monthlypurchase 
AS
BEGIN
	SELECT   Sum(OrderAmount) AS OrderAmount
FROM    Purchases WHERE MONTH(getDate()) = Month(OrderDate)
END


I want to Pass this OrderAmount from Controller to View.


Pls help me.

Thanks in advance.

What I have tried:

for This I used below in Controller:

<pre lang="HTML">ViewBag.orderAmount = db.Monthlypurchase();


in View I used the below:

HTML
@ViewBag.orderAmount


but I not getting the value instead I get the below error code:

System.Data.Entity.Core.Objects.ObjectResult`1[System.Nullable`1[System.Decimal]]
Posted
Updated 19-Jun-20 12:04pm
Comments
[no name] 22-Jun-20 7:57am    
can you share the controller code.

1 solution

Anyway I changed this line
ViewBag.OrderAmounts = db.Monthlypurchase();

to
ViewBag.OrderAmounts = db.Monthlypurchase().FirstOrDefault();


and it fixed the issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900