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

Markup to show how to inject Options in Configuration document #437

Closed
guardrex opened this issue Sep 11, 2015 · 4 comments
Closed

Markup to show how to inject Options in Configuration document #437

guardrex opened this issue Sep 11, 2015 · 4 comments
Milestone

Comments

@guardrex
Copy link
Collaborator

@danroth27 @MiKom @omarpando

I just ran into a lack of knowledge (dotnet/aspnetcore#916) on what to inject into the view for Options. I thought I'd mention that a little markup showing how to do it at ...

http://docs.asp.net/en/latest/fundamentals/configuration.html#using-options-and-configuration-objects

... might be very helpful. For your example, it might be something like ...

@inject IOptions<MyOptions> optionsAccessor
<html lang="en-US">
    <head>
        <title>Options Markup</title>
    </head>
    <body>
        <div>...@(optionsAccessor.Options.Option1)...</div>
    </body>
</html>
@Rick-Anderson
Copy link
Contributor

Good suggestion.

@Rick-Anderson Rick-Anderson self-assigned this Oct 10, 2015
@Rick-Anderson Rick-Anderson removed their assignment Nov 4, 2015
@danroth27 danroth27 added this to the Backlog milestone Dec 4, 2015
@danroth27 danroth27 added the bug label May 19, 2016
@Rick-Anderson Rick-Anderson removed the bug label Dec 17, 2016
@Rick-Anderson
Copy link
Contributor

@guardrex can you provide a sample project? No hurry.

@Rick-Anderson
Copy link
Contributor

@danroth27 is this something we want to add to the document or sample? Wouldn't it be better to pass the options in a model from the action method?

@guardrex
Copy link
Collaborator Author

guardrex commented Dec 17, 2016

@Rick-Anderson

Under the section Using Options and configuration objects and immediately after the line ...

The HomeController.Index method returns option1 = value1_from_json, option2 = 2.

Something like this could be mentioned (with a View added to the current UsingOptions sample), which ties into the example just provided ...

You can also inject IOptions<TOptions> directly into a Razor view:

@using Microsoft.Extensions.Options
@inject IOptions<MyOptions> OptionsAccessor
<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>Options Injection into a View</title>
</head>
<body>
    <h1>Options Injection into a View</h1>
    <p>
        option1 = @OptionsAccessor.Value.Option1, option2 = @OptionsAccessor.Value.Option2
    </p>
</body>
</html>

Could possibly add an image of a browser rendering this, but it probably isn't necessary.

If you want to see that in a PR, let me know.

scottaddie pushed a commit that referenced this issue Sep 6, 2017
* Update UsingOptions sample app

Takes sample to 2.0

* Update with view option injection

Fixes #437

Update

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

No branches or pull requests

3 participants