Вопрос

I have the following code which returns one of the 3 options ("Please check availability","Low Stock" or "Available") in a controller. How can I change the view (2nd part in order to display a link "here" that will open a new window to an external url like "www.google.com" ?

First part is the controller , second part the view. Thank you

    if (model.ShowInventoryAvailability)
            {
                //  Check to see if the system allows for webbackorder.  If it does then we will say that we have 'available' inventory.
                if (ApplicationSetting.GetByNameBoolean("Web_AllowBackOrder", true, "") && orderLine.Product.TrackInventory)
                {
                    var inv = (Int32)(orderLine.Product.QtyOnHand - totalOrdered);
                    if (inv <= 0)
                        line.Availability = "Please check availability" ;
                    else if (inv < model.InventoryLowStockQuantity)
                        line.Availability = "Low Stock";
                    else
                        line.Availability = "Available";
                }
                else
                { }


            }

    @if (Model.ShowInventoryAvailability)
                { 
                    <td class="os-availability">
                        @cartLine.Availability

                    </td>
                }
Это было полезно?

Решение

Assuming you want to add the url link when there is no stock you can check your text status or you could also add another property to the Model like the actual quantity and control the conditional statement via that property.

@if (Model.ShowInventoryAvailability)
{
     <td class="os-availability">
     if (cartLine.Availability == "Please check availability")
     { 
          @Html.Link("http://www.google.com", "Here");
     }
     else
     {
          @cartLine.Availability
     }
     </td>
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top