Click here to Skip to main content
14,484,894 members
   

ASP.NET

 
GeneralRe: Some GridView controls are running empty rows. Any ideas to fix Pin
Richard MacCutchan25-Feb-20 21:22
mveRichard MacCutchan25-Feb-20 21:22 
AnswerRe: Some GridView controls are running empty rows. Any ideas to fix Pin
Blikkies26-Feb-20 1:19
professionalBlikkies26-Feb-20 1:19 
QuestionASP.NET + Multi Form using Textbox problem Pin
kerek224-Feb-20 21:41
Memberkerek224-Feb-20 21:41 
SuggestionRe: ASP.NET + Multi Form using Textbox problem Pin
Richard MacCutchan24-Feb-20 23:16
mveRichard MacCutchan24-Feb-20 23:16 
QuestionWhen string in a cell has double quotes those appear in Excel after export. How do I remove them? Pin
Member 1140330424-Feb-20 10:19
MemberMember 1140330424-Feb-20 10:19 
AnswerRe: When string in a cell has double quotes those appear in Excel after export. How do I remove them? Pin
Member 1140330424-Feb-20 11:26
MemberMember 1140330424-Feb-20 11:26 
Rant[REPOST] When string in a cell has double quotes those appear in Excel after export. How do I remove them? Pin
Richard Deeming25-Feb-20 2:27
mveRichard Deeming25-Feb-20 2:27 
Questionreturning null value from populated selectlist with DB data Pin
ElenaRez21-Feb-20 21:11
MemberElenaRez21-Feb-20 21:11 
I'm implementing asp.net core MVC project. In my controller class called ApiApplicant, Create method, I have 3 selectlists that its items should be populated from a table called APIApplicantHistory. My models and create method and view are implemented like following:


using System.Collections.Generic;

namespace CSDDashboard.Models
{
public partial class Apiapplicant
{
public Apiapplicant()
{
ApiApplicantHistory = new HashSet<apiapplicanthistory>();
}

public int Id { get; set; }
public string ApiRequestDate { get; set; }
public int? ApiRequestNo { get; set; }
public int? Apiid { get; set; }
public int? ApplicantId { get; set; }
public int? GateId { get; set; }
public string NocRequestDate { get; set; }
public string NocRequestNo { get; set; }
public string Url { get; set; }
public string Description { get; set; }
public bool? IsDeleted { get; set; }

public virtual Api Api { get; set; }
public virtual Applicant Applicant { get; set; }
public virtual Gate Gate { get; set; }
public virtual ICollection<apiapplicanthistory> ApiApplicantHistory { get; set; }
}
}

using System;
using System.Collections.Generic;

namespace CSDDashboard.Models
{
public partial class ApiApplicantHistory
{
public int Id { get; set; }
public int? ApiApplicantId { get; set; }
public string Date { get; set; }
public int? SentResponseType { get; set; }
public int? UnconfirmedReason { get; set; }
public int LastReqStatus { get; set; }
public string Description { get; set; }

public virtual Apiapplicant ApiApplicant { get; set; }
public virtual EntityType LastReqStatusNavigation { get; set; }
public virtual EntityType SentResponseTypeNavigation { get; set; }
public virtual EntityType UnconfirmedReasonNavigation { get; set; }
}
}


using System;
using System.Collections.Generic;

namespace CSDDashboard.Models
{
public partial class EntityType
{
public EntityType()
{
ApiApplicantHistoryLastReqStatusNavigation = new HashSet<apiapplicanthistory>();
ApiApplicantHistorySentResponseTypeNavigation = new HashSet<apiapplicanthistory>();
ApiApplicantHistoryUnconfirmedReasonNavigation = new HashSet<apiapplicanthistory>();
}

public int Id { get; set; }
public string Name { get; set; }
public string EntityKey { get; set; }

public virtual ICollection<apiapplicanthistory> ApiApplicantHistoryLastReqStatusNavigation { get; set; }
public virtual ICollection<apiapplicanthistory> ApiApplicantHistorySentResponseTypeNavigation { get; set; }
public virtual ICollection<apiapplicanthistory> ApiApplicantHistoryUnconfirmedReasonNavigation { get; set; }

}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CSDDashboard.Models
{
public class APIApplicantViewModel
{
public Apiapplicant apiApplicantvm { get; set; }

public ApiApplicantHistory apiApplicantHistoryvm { get; set; }
}
}


public class ApiapplicantsController : Controller
{
private readonly CSSDDashboardContext _context;

public ApiapplicantsController(CSSDDashboardContext context)
{
_context = context;
}

public IActionResult Create()
{

ViewData["sentResponseType"] = new SelectList(_context.EntityType.Where(g => g.EntityKey == "sentResponseType")
        .Include(x => x.ApiApplicantHistoryLastReqStatusNavigation).ToList(), "ID", "name");

ViewData["unconfirmedReason"] = new SelectList(_context.EntityType.Where(g => g.EntityKey == "unconfirmedReason").ToList(), "ID", "name");
ViewData["lastReqStatus"] = new SelectList(_context.EntityType.Where(g => g.EntityKey == "lastRequestStatus").ToList(), "ID", "name");

return View();

}
}

And a part of create view implementation:



@modelCSDDashboard.Models.APIApplicantViewModel

@{
ViewData["Title"] = "create";
}






























@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

In create method, all the viewData are filled with the correct related data but the problem is existing in Create view, after running the project an error like below is shown in Create page:

An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an object.

After debugging the code I understand that In create view, apiApplicantvm is not null but
ViewBag.sentResponseType
returns null and the above error is because of that. I appreciate if anyone could tells me how to fix the problem.
QuestionASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
Mou_kol18-Feb-20 8:32
MemberMou_kol18-Feb-20 8:32 
AnswerRe: ASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
jkirkerx19-Feb-20 9:15
professionaljkirkerx19-Feb-20 9:15 
GeneralRe: ASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
Mou_kol19-Feb-20 9:41
MemberMou_kol19-Feb-20 9:41 
AnswerRe: ASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
F-ES Sitecore19-Feb-20 23:01
mveF-ES Sitecore19-Feb-20 23:01 
GeneralRe: ASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
Mou_kol21-Feb-20 22:36
MemberMou_kol21-Feb-20 22:36 
GeneralRe: ASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
F-ES Sitecore23-Feb-20 22:46
mveF-ES Sitecore23-Feb-20 22:46 
GeneralRe: ASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
F-ES Sitecore23-Feb-20 22:52
mveF-ES Sitecore23-Feb-20 22:52 
AnswerRe: ASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
Richard Deeming20-Feb-20 0:23
mveRichard Deeming20-Feb-20 0:23 
GeneralRe: ASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
Mou_kol21-Feb-20 22:40
MemberMou_kol21-Feb-20 22:40 
GeneralRe: ASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
Bohdan Stupak23-Feb-20 0:19
professionalBohdan Stupak23-Feb-20 0:19 
GeneralRe: ASP.Net MVC: When to use HttpGet and when to use HttpPost for action Pin
Richard Deeming23-Feb-20 21:16
mveRichard Deeming23-Feb-20 21:16 
QuestionUpdating two related tables in asp.net core Pin
ElenaRez16-Feb-20 18:35
MemberElenaRez16-Feb-20 18:35 
QuestionBinding combox in gridview with selected value of another comboBox Pin
BikerMonkey14-Feb-20 9:01
professionalBikerMonkey14-Feb-20 9:01 
QuestionHow to get a field's value from a linq query Pin
ElenaRez12-Feb-20 3:09
MemberElenaRez12-Feb-20 3:09 
AnswerRe: How to get a field's value from a linq query Pin
Richard Deeming12-Feb-20 4:45
mveRichard Deeming12-Feb-20 4:45 
QuestionStill having some display problems Pin
samflex7-Feb-20 5:36
Membersamflex7-Feb-20 5:36 
QuestionHow to set starting page or controller method of a web application when we are deploying the React or Angular or Ember applications Pin
simpledeveloper6-Feb-20 14:35
Membersimpledeveloper6-Feb-20 14:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.