Click here to Skip to main content
15,885,546 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Capture Search Engine Keyword Pin
F-ES Sitecore13-Mar-19 1:02
professionalF-ES Sitecore13-Mar-19 1:02 
QuestionCommunication between 2 MVC API's on the same server Pin
Fred28345-Mar-19 21:19
Fred28345-Mar-19 21:19 
AnswerRe: Communication between 2 MVC API's on the same server Pin
Afzaal Ahmad Zeeshan6-Mar-19 1:34
professionalAfzaal Ahmad Zeeshan6-Mar-19 1:34 
GeneralRe: Communication between 2 MVC API's on the same server Pin
Fred28346-Mar-19 2:03
Fred28346-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
Fred28346-Mar-19 2:20 
QuestionOpenID, ADSF, custom LoginID Pin
Super Lloyd28-Feb-19 14:52
Super Lloyd28-Feb-19 14:52 
QuestionUsing SelectList for dropdown binding (ASP.NET Core) Pin
Member 1416479527-Feb-19 4:42
Member 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
Member 1416479527-Feb-19 8:20 
QuestionCapture and report JavaScript errors Pin
dataminers25-Feb-19 21:46
dataminers25-Feb-19 21:46 
QuestionASP.Net Core separate API and UI projects Pin
Mycroft Holmes14-Feb-19 13:18
professionalMycroft Holmes14-Feb-19 13:18 
AnswerRe: ASP.Net Core separate API and UI projects Pin
Json Dev23-Feb-19 2:33
Json Dev23-Feb-19 2:33 
GeneralRe: ASP.Net Core separate API and UI projects Pin
Mycroft Holmes23-Feb-19 11:23
professionalMycroft Holmes23-Feb-19 11:23 
GeneralRe: ASP.Net Core separate API and UI projects Pin
Json Dev23-Feb-19 11:55
Json Dev23-Feb-19 11:55 
GeneralRe: ASP.Net Core separate API and UI projects Pin
Mycroft Holmes23-Feb-19 14:55
professionalMycroft Holmes23-Feb-19 14:55 
GeneralRe: ASP.Net Core separate API and UI projects Pin
Json Dev23-Feb-19 16:49
Json Dev23-Feb-19 16:49 
QuestionC# CREATING SIMPLE ORACLE API Pin
sellol12-Feb-19 1:20
sellol12-Feb-19 1:20 
AnswerRe: C# CREATING SIMPLE ORACLE API Pin
Richard MacCutchan12-Feb-19 5:28
mveRichard MacCutchan12-Feb-19 5:28 
GeneralRe: C# CREATING SIMPLE ORACLE API Pin
sellol12-Feb-19 5:37
sellol12-Feb-19 5:37 
GeneralRe: C# CREATING SIMPLE ORACLE API Pin
Richard MacCutchan12-Feb-19 5:51
mveRichard MacCutchan12-Feb-19 5:51 
GeneralRe: C# CREATING SIMPLE ORACLE API Pin
sellol12-Feb-19 6:01
sellol12-Feb-19 6:01 
GeneralRe: C# CREATING SIMPLE ORACLE API Pin
Richard MacCutchan12-Feb-19 6:05
mveRichard MacCutchan12-Feb-19 6:05 
AnswerRe: C# CREATING SIMPLE ORACLE API Pin
Mycroft Holmes12-Feb-19 13:52
professionalMycroft Holmes12-Feb-19 13:52 
AnswerRe: C# CREATING SIMPLE ORACLE API Pin
jschell23-Feb-19 10:59
jschell23-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.