Professional Documents
Culture Documents
Name:-Zain Ul Abdin Section: - BSIT (6C) Arid No: - 2018-Arid-1340 Submitted To: - MR Ahsan Quiz No: - 02
Name:-Zain Ul Abdin Section: - BSIT (6C) Arid No: - 2018-Arid-1340 Submitted To: - MR Ahsan Quiz No: - 02
Name:-Zain Ul Abdin Section: - BSIT (6C) Arid No: - 2018-Arid-1340 Submitted To: - MR Ahsan Quiz No: - 02
Section:- BSIT(6C)
Arid No:- 2018-Arid-1340
Submitted To:- Mr Ahsan
Quiz No:- 02
Controller
using System.Collections.Generic;
using System.Web.Mvc;
using WebApplication88.Models;
using WebApplication88.DAL;
namespace WebApplication8.Controllers
{
public class UserController : Controller
{
// GET: User
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(User user)
{
ViewBag.isPost = true;
if (rowsEffected > 0)
{
ViewBag.db = true;
}
else
{
ViewBag.db = false;
}
return View();
}
}
}
View
@model WebApplication88.Models.User
<h2>Index</h2>
<body>
@using (Html.BeginForm())
{
<table>
<tr>
<td> Title </td>
<td> @Html.TextBoxFor(x=>x.title) </td>
</tr>
<tr>
<td> Category </td>
<td> @Html.TextBoxFor(x => x.category) </td>
</tr>
<tr>
<td> Publish Type </td>
<td> @Html.TextBoxFor(x => x.pbt) </td>
</tr>
<tr>
<td><input type="submit" value="Add User" /></td>
</tr>
</table>}
@if (ViewBag.isPost != null)
{
<p>Data Submitted Successfully</p>}
@if (ViewBag.db != null && ViewBag.db)
{
<p>Data Saved Successfully</p>}
</body>
MODEl
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication88.Models
{
public class User {
public string title { get; set; }
public string category { get; set; }
public int pbt { get; set; }
}
}
Class
using System;
using System.Data.SqlClient;
using WebApplication88.Models;
namespace WebApplication88.DAL
{
public class UserEntity
{
string ConnectionString = @"Data Source=DESKTOP-L0E8OUH;Initial
Catalog=AuthorBooks;Integrated Security=True";
public int insert(User user)
{
int rowsEffected = 0;
try
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();