Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use SelectListItem for dropdown #21

Closed
MKI-Miro opened this issue Aug 3, 2017 · 9 comments
Closed

How to use SelectListItem for dropdown #21

MKI-Miro opened this issue Aug 3, 2017 · 9 comments
Labels

Comments

@MKI-Miro
Copy link

MKI-Miro commented Aug 3, 2017

Hi

I need to use dropdown. So for example i need to add this
public IEnumerable<SelectListItem> CreditCards { get; set;
to
CustomerViewModel
but SelectListItem is part of Microsoft.AspNetCore.Mvc.ViewFeatures.dll

Is it correct to add MVC dependency to Application project?

Thanks

@thiagolunardi
Copy link
Contributor

thiagolunardi commented Aug 3, 2017

Hi @MKI-Miro

Is it correct to add MVC dependency to Application project?

God no! You Application should not be aware of what kind of client is consuming it - web, mobile, windows, don't care. So, no dependency at all on it. The Application project should be ready to serve any kind of client.

About the SelectListItem...

Actually, this depends on you. You can extend the CustomerViewModel class in you presentation layer and add more properties to it.

You also can - but shouldn't - create the SelectListItem directly at your Razor view.

@MKI-Miro
Copy link
Author

MKI-Miro commented Aug 3, 2017

but I cannot add SelectListItem to CustomerViewModel.... (because of dependency to MVC)

so what is the solution?

@thiagolunardi
Copy link
Contributor

You extend it.

At you UI.Web project, create a file /CustomViewModels/MyCustomerViewModel.cs

public class MyCustomerViewModel : CustomerViewModel
{
    public IEnumerable<SelectListItem> CrediCards { get; set; }
}

@MKI-Miro
Copy link
Author

MKI-Miro commented Aug 3, 2017

but CustomerAppService does not reference UI.Web

@thiagolunardi
Copy link
Contributor

Ok, we are missing some info here.

What you have right now at your Application.ViewModels.CustomerViewModel?

Can you share the code here?

@MKI-Miro
Copy link
Author

MKI-Miro commented Aug 3, 2017

nothing :) it was just wondering how to do it. All I have is your code. So maybe you can extend your application with one dropdown.

@thiagolunardi
Copy link
Contributor

But I already show you that with MyCustomerViewModel sample.

What you didn't get it?

@thiagolunardi
Copy link
Contributor

Can we close your issue, @MKI-Miro ?

@EduardoPires
Copy link
Owner

I think @thiagolunardi helped you, if you have more questions please reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants