|
Something is null somewhere in your code when it shouldn't be.
Since you haven't told us which line of your view the exception is thrown from, we can't give you any more details.
Debug your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello sir am attaching my homeController code to this file check it and let me know where should i make the changes and how at_least give me code_snippet for making changes into my code instead.
//HomeController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestMvcApplication.Models;
namespace TestMvcApplication.Controllers
{
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
// get regester
public ActionResult Register()
{
return View();
}
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Register(tblEmployee obj)
{
if (ModelState.IsValid)
{
MYDBEntities1 db = new MYDBEntities1();
db.tblEmployees.Add(obj);
db.SaveChanges();
}
return View(obj);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(UserProfile objUser)
{
if (ModelState.IsValid)
{
using (MYDBEntities1 db = new MYDBEntities1())
{
var obj = db.UserProfiles.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();
if (obj != null)
{
Session["UserID"] = obj.UserId.ToString();
Session["UserName"] = obj.UserName.ToString();
return RedirectToAction("Register");
}
}
}
return View(objUser);
}
[HttpGet]
public ActionResult Edit(int id)
{
return View();
}
|
|
|
|
|
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 38:
Line 39:
Line 40: @foreach (var item in Model) {
Line 41:
Line 42:
Source File: c:\Users\Bittu\Documents\Visual Studio 2013\Projects\TestMvcApplication\TestMvcApplication\Views\Home\Index.cshtml Line: 40
|
|
|
|
|
You're not passing a model to the view. Therefore, it's null , and you'll get a NullReferenceException when you try to iterate over it.
Your Index action needs to create an instance of the appropriate type, and pass it to the View method.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
Is there a way to disable page zoom and enable only image zoom of the page in a touch screen?
Thanks
|
|
|
|
|
Even though you may find an way to do it with code for your picture box or so, you cannot control browser functionality user can still zoom in/out your web page
modified 20-Sep-20 21:01pm.
|
|
|
|
|
I don't get it here. I've always used HttpCookies to store multiple values in them
But using Cookie, it seems you can only store 1 value.
What I'm trying to do:
I have a mvc view called Bug Report. You click the button and it runs the Diag Controller with an action that uses HttpWebRequest and prior was WebClient. I changed it to transmit a cookie in the header, because WebClient was too basic.
On the page that is getting read, I have an home made security attrubute that uses OnActionExecuting and the ActionExecutingContext. If the request doesn't contain the session variable, it gets kicked out to Logout.
So to the best of my research, you can make a cookie container with multiple cookies.
This works fine, but I wanted to refine it more...
With HttpCookies, I can send 1 cookie with the 4 values, but with cookie, I have to send each cookie separate. I don't understand this part.
CookieContainer container = new CookieContainer();<br />
container.Add(new Cookie("a", httpCookie["a"]) { Domain = target.Host });
container.Add(new Cookie("b", httpCookie["b"]) { Domain = target.Host });
container.Add(new Cookie("c", httpCookie["c"]) { Domain = target.Host });
container.Add(new Cookie("d", "true") { Domain = target.Host });
var webRequest = (HttpWebRequest)WebRequest.Create(rUrl);
webRequest.CookieContainer = container;
using (var response = (HttpWebResponse)webRequest.GetResponse())
{
model.Page_HTML = response.ToString();
}
So I wrote this, the main cookie, but I can't figure out how to store 4 records in it.
Cookie cookie = new Cookie() {
Name = "Main",
Expires = DateTime.Now.AddMinutes(1),
Domain = target.Host,
HttpOnly = true,
Secure = true
};
On the OnActionExecuting side, I figured how to read the cookies. But it seems sort or silly to read 4 cookies. It looks like on this side I can just read a HttpCookie of any format.
HttpCookie cookie_A = filterContext.RequestContext.HttpContext.Request.Cookies.Get("a");
So my question is:
Am I beating a dead horse with a stick here and I should just be happy that the 4 cookies work?
If it ain't broke don't fix it
|
|
|
|
|
Multi-valued cookies are not a standard feature. The HttpCookie class "fakes" support by serializing the values to a string similar to a query string:
HttpCookie - Reference Source[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard!
So in other words, an HttpCookie write can write an array of values that is parsed when read by HttpCookie.
Sort of a way to make cookies easier for beginners and take the complexity out of it, or for compatibility with some other standard written by other programs. Or maybe proprietary to just reading our own cookies in asp.net - most likely answer. Sort of like those dumb html objects in webforms.
And perhaps cookie is the standard way to read and write a cookie.
Glad I didn't beat the horse more with my stick on the subject.
If it ain't broke don't fix it
|
|
|
|
|
Hi,
I have a Kendo grid I am have a dropdown as the first element of it, I want to get the selected text or value of those all drop downs if they are selected. If they are not selected there is no need to count them.
I am using jQuery to do it, tried many options so far there is no luck. Grid is very big, hence I am just putting only the code where I am trying to access it.
This is is how I am trying it, so far no luck, any help would be very helpful, thanks in advance.
var grid = $( "#budgetdGrid" );
var dataSource = grid.dataSource;
var columns = $("#budgetdGrid").data("kendoGrid").columns;
var rows = $("#budgetdGrid").data("kendoGrid").rows;
var noOfCols = columns.length;
grid.items().each(function(a) {
alert(a.text())
});
I am trying to access it within this function:
function onLineDropDownChange(e) {<br />
//alert(e.sender.select())
//alert(e.sender.text());
var grid = $( "#budgetdGrid" );
var dataSource = grid.dataSource;
var columns = $("#budgetdGrid").data("kendoGrid").columns;
var rows = $("#budgetdGrid").data("kendoGrid").rows;
var noOfCols = columns.length;
grid.items().each(function(a) {
alert(a.text())
});
//alert(e.sender.select().val())
//rows.each(function(e) {
// var grid = $("#budgetdGrid").data("kendoGrid");
// var dataItem = grid.dataItem(this);
// alert(dataItem);
//})
var tr = this.element.closest("tr");
var line_no="";
var prev_line = [];
// var line_arr = ['200', '201', '101a-cw', '101a-mc', '70p-cw', '70p-mc'];
var lin_val = tr.find("input[id^='inputLine_']").val();
if ( lin_val != "" && lin_val != 'undefined') {
line_no = tr.find("input[id^='inputLine_']").data("kendoDropDownList").text().substr(0, tr.find("input[id^='inputLine_']").data("kendoDropDownList").text().indexOf('('));
}
if (lin_val != '' && line_no != '') {
$("#doeGrid").find("#budgetdGrid tbody").find('tr').each(
function () {
var id = $(this).find("input[id^='inputLine_']").val();
if (id == lin_val && lin_val != "" && id != "") {
prev_line.push(id);
}
});
if (prev_line.length > 1) {
alert("You have already selected the Line Item in the previous rows");
}
else {
if ((line_no.substr(0, line_no.indexOf('-')) == '200') || (line_no.substr(0, line_no.indexOf('-')) == '201') || (line_no == '101a-cw') ||
(line_no == '101a-mc') || (line_no == '70p-cw') || (line_no == '70p-mc') || (line_no.substr(0, line_no.indexOf('-')) == '202' && '@Session["FiscalYearCode"]'=='FY 2015-2016')||
(line_no.substr(0, line_no.indexOf('-')) == '204' && '@Session["FiscalYearCode"]'=='FY 2015-2016')||
(line_no.substr(0, line_no.indexOf('-')) == '203' && '@Session["FiscalYearCode"]'=='FY 2015-2016') ||
(line_no.substr(0, line_no.indexOf('-')) == '205' && '@Session["FiscalYearCode"]'=='FY 2015-2016'))
//if (containsLine(line_no, line_arr))
{
if (containsAny('@Model.Service_Code', [30, 33, 34, 43, 51, 52]) && '@Model.Program_Code' >= 87) {
tr.find("input[name^='txt_budgt']").removeAttr("disabled = 'disabled'");
tr.find("input[name=txt_IndivUOS]").removeAttr("disabled = 'disabled'");
}
else if (('@Model.Service_Code' == 48 && '@Model.Program_Code' >= 87)) {
tr.find("input[name^='txt_budgt']").removeAttr("disabled = 'disabled'");
tr.find("input[name=txt_IndivUOS]").removeAttr("disabled = 'disabled'");
tr.find("input[name=txt_NtpGrp]").removeAttr("disabled = 'disabled'");
tr.find("input[name=txt_NtpDos]").removeAttr("disabled = 'disabled'");
}
else {
tr.find("input[name^='txt_budgt']").removeAttr("disabled = 'disabled'");
}
}
else if (('@Session["FiscalYearCode"]'=='FY 2016-2017') || ('@Session["FiscalYearCode"]'=='FY 2017-2018'))
{
tr.find("input[name^='txt_dirCst']").removeAttr("disabled = 'disabled'");
}
else {
tr.find("input[name^='txt_budgt']").removeAttr("disabled = 'disabled'");
}
}
}
else {
alert("Please Choose Proper Line Item");
}
}
This function will be called when there is any change in the Grid, onchange but when change occurs it has to loop through the whole grid and then find out the selected text or values of the dropdowns then it will be acted upon the selected items of the dropdowns.
Please any help would be very very supportive - thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
|
I don't have membership for Telerik forum, only licensed members are eligible to put questions, I am also searching but if somebody can help me, it would be a great help - thanks buddy.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
indian143 wrote: only licensed members are eligible to put questions
But surely only licensed members are eligible to use the controls?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes but my Company has the license not me, hence the problem Rick (do you go with Rick or Richard)
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hi,
I could able to get up to here so far but the val or text functions are not working on those items. Here is the below code I did,
var dataSource = $("#budgetdGrid").data("kendoGrid").dataSource;
var data = dataSource.data(); // or this.view();
for (var i = 0; i < data.length; i++) {
alert(data[i][0].val());
}
But the alert(data[i][0].val()); is throwing error, I tried with text also, that one also is throwing errors saying that those functions are not supported etc. budgetdGrid is the Kendo Grid, and the first element of that (I mean index) 0 is dropdown list selected text I want to get, for all the rows, I am looping through rows correctly here that the number of rows 8 are matching with what I have in Grid, but I am not able to get the selected items text value.
Any help would be greatly helpful, thanks in advance.
I have tried in the following way also, but its pulling out only the value but not the selected text, I need the selected text rather than value because I need to compare with text but not with the value:
$("#doeGrid").find("#budgetdGrid tbody").find('tr').each(
function () {
var id = $(this).find("input[id^='inputLine_']").val();
var txt = $(this).find("input[id^='inputLine_']").text();
alert(id);
alert(txt)
if (id == lin_val && lin_val != "" && id != "") {
prev_line.push(id);
}
});
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
-- modified 21-Mar-18 14:19pm.
|
|
|
|
|
I have a gridview with a score column (4).
I am trying to get the total score.
Thanks anyone..please
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID,EP,supEmail" DataSourceID="SQLDuties" OnPreRender="GridView1_PreRender" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" />
<asp:TemplateField HeaderText="Duties" SortExpression="Duties">
<EditItemTemplate>
<asp:Label ID="EditDuties" runat="server" Text='<%# Bind("Duties") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Duties") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Agreed" SortExpression="Agreed">
<EditItemTemplate>
<asp:Label ID="EditTargets" runat="server" Text='<%# Bind("Agreed") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Agreed") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Score (1-5)" SortExpression="Score">
<EditItemTemplate>
<asp:TextBox ID="txtScore" runat="server" Text='<%# Bind("Score") %>' TextMode="Number"></asp:TextBox>
<asp:RequiredFieldValidator ID="RFVScore" runat="server" ErrorMessage="Score Require" ControlToValidate="txtScore" ForeColor="red"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator2" runat="server" ErrorMessage="1 to 5" MaximumValue="5" MinimumValue="1" ControlToValidate="txtScore" ForeColor="red"></asp:RangeValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Score") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Comment" HeaderText="Comment" SortExpression="Comment" />
<asp:BoundField DataField="EP" HeaderText="EP" SortExpression="EP" Visible="False" />
<asp:BoundField DataField="supEmail" HeaderText="supEmail" SortExpression="supEmail" Visible="False" />
</Columns>
<EmptyDataTemplate>
<br />
</EmptyDataTemplate>
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int total = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
total = total + Convert.ToInt32( e.Row.Cells[4].Text.ToString());
}
Response.Write(total.ToString());
}
|
|
|
|
|
e.Row.Cells[4].Text will only work for BoundField Columns. For accessing TemplateFields , you need to use FindControl() method. For example:
var score = ((Label)e.Row.Cells[4].FindControl("Label3")).Text;
|
|
|
|
|
I am hoping someone can explain to me the rationale behind the Page.RegisterStartupScript method... What does it achieve that simply writing your script to a Literal doesn't? I've never had a reason to use it - if I want to add JavaScript to a page I simply do that. I am no doubt being very silly, but..
|
|
|
|
|
It ensures the script is only registered once.
For example, if you have a UserControl, you could have multiple instances of it on the page. Writing the script to a literal would output one copy of the script for each instance of the control, whereas RegisterStartupScript would (normally) only output one copy.
It also ensures that the script is rendered at the bottom of the form, rather than scattered throughout the markup. Not a huge issue, but very satisfying if you have OCD.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
OK... so if you have multiple user controls with scripts in then, yes, I see that makes sense. Otherwise though... (and I generally place my literal at the bottom of the page anyway )
Ta.
|
|
|
|
|
In addition to ensuring the script is only written once, if you are writing a user control then you can only control the mark-up inside that control, so it wouldn't be possible to inject a label for js at the bottom of the page.
My biggest issue with RegisterStartupScript etc is the name, it should be changed to RegisterStartupScriptPleaseNoteThatYourJSIsNOTBeingExecutedImmediatelyInServerSideCode
|
|
|
|
|
Hi, I am creating a scheduling website for a university project using Visual Studios. It is a website for managing shifts and schedules and the main event of the website is the scheduler which will display employee shifts within it. I have never created a timetable/calendar/scheduler in Visual Studios before. How can I produce a simple scheduler in C# that can be modified and links to a database?
|
|
|
|
|
|
Hi Vincent,
Thanks for the reply. I have searched Google for resources and I couldn’t find what I wanted; so I turned to forums with the hope that people who have successfully created schedules in Visual Studios could give me their knowledge.
The links that you gave me are just what I need. I will attempt compiling the code and editing it to suit my needs. Thanks again.
|
|
|
|
|
Maybe you could look at quartz.net
and
Hangfire
|
|
|
|