Controller.cs
Email ed = new Email();
var model = ed.sendemail(Session["username"].ToString()).ToList();
return View(model);
model
email.cs
public List
{
List
using (var cn = new SqlConnection(@"Data Source=localhost;Initial Catalog=master;Integrated Security=True"))
{
try
{
string query = @"select receiver1,receiver2,subject,message,dofsen,status from send_email where receiver1='" + username + "' or receiver2='" + username + "'";
cn.Open();
var cmd = new SqlCommand(query, cn);
var reader = cmd.ExecuteReader();
while (reader.HasRows)
{
if (reader.Read())
{ // to , cc, message, subject, sendingdate, status
Email ed = new Email(reader.GetString(0), reader.GetString(1), reader.GetString(2),reader.GetString(3) ,reader.GetDateTime(4), reader.GetString(5));
tt.Add(ed);
}
}
return tt;
}
catch (Exception er)
{
string t = er.ToString();
return null;
}
finally
{
cn.Close();
}
}
}
home.cshtml
@model email.Models.Email
@{
ViewBag.Title = "SentMail";
Layout = null;
}
@using (Html.BeginForm())
{
@Html.ActionLink("BACK", "Home")
|
@Html.ActionLink("COMPOSE MAIL", "ComposeMail")
|
@Html.ActionLink("CHANGE PASSWORD", "uchangePassword")
|
@Html.ActionLink("UPDATE SECURITY ANSWER", "UpdateSecurityAnswer")
|
@Html.ActionLink("Sign Out", "Logout")
@Html.LabelFor(u => u.To) | @Html.LabelFor(u => u.Cc) | @Html.LabelFor(u => u.Subject) | @Html.LabelFor(u=> u.Message) | @Html.LabelFor(u=>u.SendingDate) | @Html.LabelFor(u => u.Status) |
|---|---|---|---|---|---|
@Html.TextBoxFor(u=>u.To[i]) | @Html.TextBoxFor(u => u.Cc[i]) | @Html.TextBoxFor(u=> u.Subject[i]) | @Html.TextBoxFor(u => u.Message[i]) | @Html.TextBoxFor(u => u.SendingDate) | @Html.TextBoxFor(u => u.Status[i]) |
}
Jignesh TrivediPosted Mar 12, 2014, 12:08 AM
try to change code line
@for (int i = 1; i <= ViewBag.tt.Count();i++)
{
....
....
}
to
@for (int i = 1; i <= @Model.Count();i++)
{
....
....
}
hope this will help u.
vineet sharmaPosted Mar 11, 2014, 10:11 PM
Jignesh TrivediPosted Mar 11, 2014, 8:25 AM
I think, you have to call sendemail method instead of receivedMessage
Controller.cs
Email ed = new Email();
var model = ed.sendemail(Session["username"].ToString()).ToList();
return View(model);
also can you please share view code as well.
vineet sharmaPosted Mar 11, 2014, 8:19 AM
Jignesh TrivediPosted Mar 11, 2014, 3:04 AM
hi,
You can use Entity Framework to perform CRUD operation.
Please refer
http://www.codeproject.com/Articles/363040/An-Introduction-to-Entity-Framework-for-Absolute-B
http://www.dotnet-tricks.com/Tutorial/entityframework/U60K050312-Introduction-to-Entity-Framework.html
hope this will help you.
Jaganathan BantheswaranPosted Mar 11, 2014, 2:09 AM