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