This should be a very easy question as I'm a noob and almost have it figured out myself. I'm authenticating against info in a database and I want to simply display the row's data to the view. I'm really not sure how to, I'm assuming, create a variable in the controller that has the row's data and call that variable to the view so that I can see the rows information on the screen.
Thanks everyone, hope to get better at this soon!
My Model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace Mybasicvalidator.Models
{
public class Class1
{
[Required]
public int id { get; set; }
public string fname {get; set;}
public string lname { get; set; }
public string email { get; set; }
public string username { get; set; }
public string password { get; set; }
}
}
My Controller:
using Mybasicvalidator.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
namespace Mybasicvalidator.Controllers
{
public class homeController : Controller
{
//
// GET: /home/
[HttpGet]
public ActionResult Index()
{
return View();
return Content("Login Page");
}
[HttpPost]
public ActionResult Index(Class1 modelle)
{
if (ModelState.IsValid)
{
if (DataAccess.DAL.CheckUser(modelle.fname))
{
return RedirectToAction("Index", "profile");
}
{
return Content("FAIL");
}
}
return View();
}
}
}
MY Data Access Layer (DAL):
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
namespace Mybasicvalidator.DataAccess
{
public class DAL
{
static SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString());
public static bool CheckUser(string fname)
{
bool authenticated = false;
string query = string.Format("SELECT * FROM [tbl_user] WHERE fname = '{0}'", fname);
SqlCommand cmd = new SqlCommand(query, conn);
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
authenticated = sdr.HasRows;
conn.Close();
return (authenticated);
}
}
}
So I know that it is reading the row and checking the authentication against my row, so how do I bring the data row to the view? I'm very new to this and have tried for a week to get it going, so I would appreciate some code I can follow.
Thanks again