Click here to Skip to main content
14,269,076 members
   

ASP.NET

 
AnswerRe: Capture Search Engine Keyword Pin
F-ES Sitecore13-Mar-19 1:02
mveF-ES Sitecore13-Mar-19 1:02 
QuestionCommunication between 2 MVC API's on the same server Pin
Fred28345-Mar-19 21:19
memberFred28345-Mar-19 21:19 
AnswerRe: Communication between 2 MVC API's on the same server Pin
Afzaal Ahmad Zeeshan6-Mar-19 1:34
mveAfzaal Ahmad Zeeshan6-Mar-19 1:34 
GeneralRe: Communication between 2 MVC API's on the same server Pin
Fred28346-Mar-19 2:03
memberFred28346-Mar-19 2:03 
AnswerRe: Communication between 2 MVC API's on the same server Pin
Nathan Minier6-Mar-19 1:59
professionalNathan Minier6-Mar-19 1:59 
GeneralRe: Communication between 2 MVC API's on the same server Pin
Fred28346-Mar-19 2:20
memberFred28346-Mar-19 2:20 
QuestionOpenID, ADSF, custom LoginID Pin
Super Lloyd28-Feb-19 14:52
memberSuper Lloyd28-Feb-19 14:52 
QuestionUsing SelectList for dropdown binding (ASP.NET Core) Pin
Member 1416479527-Feb-19 4:42
memberMember 1416479527-Feb-19 4:42 
Please note I have very limited knowledge of MVC. I have found helpful articles using MVC on this topic, but am having trouble distinguishing MVC vs Core differences. For example, I found a great answer in this forum but I don't quite understand the controller portion.

I'm wanting to bind a dropdown list to a database table.

I have a Costcenters model (and in my context file I have "public virtual DbSet<costcenters> Costcenters { get; set; }"):
public partial class Costcenters
{
    public int Id { get; set; }
    public string CostcntrNo { get; set; }
    public string CostcntrName { get; set; }
    public string CostcntrMngr { get; set; }
}

I'd like to add the dropdown to my Register.cshtml page, submitting the Id but listing the CostcntrNo in the dropdown:
<select asp-for="Input.CostcntrId" class="form-control" asp-items="@(new SelectList(Model.Costcenters,"Id","CostcntrNo"))">
    <option disabled selected style="display:none">--select an option--</option>
</select>

Here's the part I believe I'm messing up on. All I've added to Register.cshtml.cs so far for this is (shortened for the question):
public List<Costcenters> Costcenters { get; set; }

[BindProperty]
public InputModel Input { get; set; }

public class InputModel
{
    [Required]
    public int CostcntrId { get; set; }
}

public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
if (ModelState.IsValid)
{
    var user = new ApplicationUser
    {
        CostcntrId = Input.CostcntrId
    }
}

Would the easiest way to complete this be to add a "LINQ query" in here?

Currently when I run this in development, I receive the "Value cannot be null" error. I may be closer than I think, but I have a poor understanding of this method so any explanation is greatly appreciated. Smile | :)
AnswerRe: Using SelectList for dropdown binding (ASP.NET Core) Pin
Richard Deeming27-Feb-19 8:10
mveRichard Deeming27-Feb-19 8:10 
GeneralRe: Using SelectList for dropdown binding (ASP.NET Core) Pin
Member 1416479527-Feb-19 8:20
memberMember 1416479527-Feb-19 8:20 
QuestionCapture and report JavaScript errors Pin
dataminers25-Feb-19 21:46
memberdataminers25-Feb-19 21:46 
QuestionASP.Net Core separate API and UI projects Pin
Mycroft Holmes14-Feb-19 13:18
memberMycroft Holmes14-Feb-19 13:18 
AnswerRe: ASP.Net Core separate API and UI projects Pin
Json Dev23-Feb-19 2:33
memberJson Dev23-Feb-19 2:33 
GeneralRe: ASP.Net Core separate API and UI projects Pin
Mycroft Holmes23-Feb-19 11:23
memberMycroft Holmes23-Feb-19 11:23 
GeneralRe: ASP.Net Core separate API and UI projects Pin
Json Dev23-Feb-19 11:55
memberJson Dev23-Feb-19 11:55 
GeneralRe: ASP.Net Core separate API and UI projects Pin
Mycroft Holmes23-Feb-19 14:55
memberMycroft Holmes23-Feb-19 14:55 
GeneralRe: ASP.Net Core separate API and UI projects Pin
Json Dev23-Feb-19 16:49
memberJson Dev23-Feb-19 16:49 
QuestionC# CREATING SIMPLE ORACLE API Pin
sellol12-Feb-19 1:20
membersellol12-Feb-19 1:20 
AnswerRe: C# CREATING SIMPLE ORACLE API Pin
Richard MacCutchan12-Feb-19 5:28
protectorRichard MacCutchan12-Feb-19 5:28 
GeneralRe: C# CREATING SIMPLE ORACLE API Pin
sellol12-Feb-19 5:37
membersellol12-Feb-19 5:37 
GeneralRe: C# CREATING SIMPLE ORACLE API Pin
Richard MacCutchan12-Feb-19 5:51
protectorRichard MacCutchan12-Feb-19 5:51 
GeneralRe: C# CREATING SIMPLE ORACLE API Pin
sellol12-Feb-19 6:01
membersellol12-Feb-19 6:01 
GeneralRe: C# CREATING SIMPLE ORACLE API Pin
Richard MacCutchan12-Feb-19 6:05
protectorRichard MacCutchan12-Feb-19 6:05 
AnswerRe: C# CREATING SIMPLE ORACLE API Pin
Mycroft Holmes12-Feb-19 13:52
memberMycroft Holmes12-Feb-19 13:52 
AnswerRe: C# CREATING SIMPLE ORACLE API Pin
jschell23-Feb-19 10:59
memberjschell23-Feb-19 10:59 

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.