Home Hiding parts of html dependant on model, not using if statement
Reply: 0

Hiding parts of html dependant on model, not using if statement

zawisza
1#
zawisza Published in 2017-12-02 15:38:41Z

In my code I use an if statement to check if the model is not null, so that I can use the same view for adding and editing new items. I have used an if statement to only render the view file button when editing the node and if it actually has a file to view. I am not entirely happy with it though. It looks terrible. I would like to avoid using if statements in my view if possible. Does anyone know how I could do that?

My code:

<div class="input-group">
            <label class="input-group-addon" asp-for="FloorPlan"></label>
            <input class="form-control" asp-for="FloorPlan" />
            @if (Model != null)
            {
                if (Model.IfFloorPlan)
                {
                    <a class="input-group-addon" asp-action="ViewFile" asp-route-id=@Model.Id asp-route-fileName="floor" target="_blank">View File</a>
                }

            }
        </div>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298036 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO