Resolved How to pass data from Controller to WebForm in ASP.NET MVC?

Anonymous

Well-known member
Joined
Sep 29, 2020
Messages
62
Programming Experience
Beginner
I am trying to learn ASP.NET MVC and ADO.NET. I am making a demo website in which there would be an admin panel. The admin would update the Daily Messages which will get reflected in the main homepage. I am using ASP.NET MVC. I have created the table in database as

C#:
create table DailyMsg(Sno int primary key, msg varchar(max));

This is my Daily Access Layer

C#:
public class DailyMsgs
{
    static string connectionString = @"data source = DELL\SQLEXPRESS01;initial catalog = amen; persist security info=True;Integrated Security = SSPI;";
    SqlConnection con = new SqlConnection(connectionString);

    DailyMsg dm = new DailyMsg();

    public string ViewDailyMessage()
    {
        SqlCommand com = new SqlCommand("sp_viewDsilyMSg", con);
        com.CommandType = CommandType.StoredProcedure;
        con.Open();
        string simpleValue = com.ExecuteScalar().ToString();
       
        con.Close();
        return simpleValue;
    }
}

My model class:



C#:
public partial class DailyMsg
{
    public int Sno { get; set; }
    public string msg { get; set; }
}


Now, I am stuck at this step. I don't know how to place this returned value simpleValue to the <h2> tag of my view.
My controller

C#:
DailyMsgs dailyMsgs = new DailyMsgs();

private amenEntities db = new amenEntities();

// GET: DailyMsgs
public ActionResult Index()
{
    return View();
}

My home page:

C#:
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
 
Last edited:
Top Bottom