prabhu p

prabhu p

  • NA
  • 181
  • 110.2k

Error :Object reference not set to an instance of an object

Feb 3 2018 9:40 AM
 
[HttpPost]
public ActionResult UserAccount(List<SelectListItem> items)
{
string Rolename = "";
int Roleid = 0;
string userid = "";
string updatedby = "";
string name = Request.Form["Txt_userid"].ToString(); //error linene  please see view  and controller //below
foreach (SelectListItem item in items)
{
if (item.Selected)
{
Rolename = item.Text;
Roleid = Convert.ToInt32(item.Value);
userid = "6090";
updatedby = "admin";
AIS.InsertRole_status(Roleid, 1, userid, updatedby);
}
else
{
Rolename = item.Text;
Roleid = Convert.ToInt32(item.Value);
userid = "6090";
updatedby = "admin";
AIS.InsertRole_status(Roleid, 0, userid, updatedby);
}
}
return View(items);
// UserAccount UA = new UserAccount();
// UA.SuperUsrChk = true;
// UA.RequestorUsrChk = false;
// // return View(new UserAccount { SuperUsrChk = true });
// return View(UA);
}
view
@model List<SelectListItem>
@{
ViewBag.Title = "UserAccount";
}
@Scripts.Render("~/bundles/jquery")
<link href="~/Content/css/font-awesome.css" rel="stylesheet" />
 
<script type="text/javascript">
$(document).ready(function () {
$('#searchrole').click(function () {
debugger
$.ajax({
url: '@Url.Action("UserAccountWithid", "Admin")',
type: 'GET',
data: { Uid: $("#Txt_userid").val() },
cache: false,
success: function (data) {
$("#contact").html(data);
$header = $('.header');
$("#div1").show();
$header1 = $('.header tr td');
var x = $header.find('td');
var k = $header1.find('div');
$('.panel-body').on('scroll', function () { $header.css('top', $(this).scrollTop()); });
//var wi = new Array();
//$('.dt tr').eq(0).find('td').each(function (e) {
// k.eq(e).width($(this).width() );
// wi.push(k.eq(e).width());
//});
$('.dt thead tr td div').each(function (e) {
k.eq(e).width($(this).width());
});
},
error: function () {
// handle ajax error
}
});
});
});
</script>
@using (Html.BeginForm("UserAccount", "Admin"))
{
<div class="container customdiv" style="width=25px">
<div class="row" style="padding:10px;">
<div class="col-lg-5">
<div class="row">
<div class="col-lg-3">UserId</div>
<div class="col-lg-7" style="z-index:3;">
<input class="form-control srchfield" id="Txt_userid" placeholder="Userid">
</div>
</div>
</div>
<div class="col-lg-5">
<div class="row">
<div class="col-lg-7" style="z-index:3;">
<button type="button" class="btn btn-primary backimg" id="searchrole" style="width:35%;">SearchRoles</button>
</div>
</div>
</div>
</div>
</div>
<div class="panel-body" id="div1" style="padding:0px; height:75%;overflow:auto;">
<table class="header table table-striped table-bordered table-responsive table-list">
<thead id="tblthead">
@for (int i = 0; i < Model.Count(); i++)
{
<tr>
<td>
@Html.CheckBoxFor(m => m[i].Selected)
</td>
<td>
@Html.DisplayFor(m => m[i].Text)
@Html.HiddenFor(m => m[i].Value)
@Html.HiddenFor(m => m[i].Text)
</td>
</tr>
}
</thead>
</table>
<br />
</div>
<div>
<input type="submit" value="Submit"/>
</div>
<div id="spinner" class="spinner" style="display:none;"><i class="fa fa-circle-o-notch fa-spin fa-4x fa-fw" aria-hidden="true"></i></div>
<script type="text/javascript" src="~/Scripts/custdropdownscript.js"></script>
}
 
 
 
 
 
 
 
 
 

Answers (1)