0

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>
                }
Charalampos Afionis
  • 193
  • 1
  • 1
  • 11

1 Answers1

0

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>
}
rclement
  • 1,664
  • 14
  • 10
  • Hi and thank you for the reply. The Model.Availability does not exist and returns error : Compiler Error Message: CS1061: 'InSite.Mvc.Models.ViewModels.CartViewModel' does not contain a definition for 'Availability' Do I have to enter something else? You assume correct that I want to show link only when there is no availability. Thank you – Charalampos Afionis Oct 30 '13 at 12:52
  • try changing `if (Model.Availability == "Please check availability")` to `if (Model.Availability != null && Model.Availability == "Please check availability")` – jim tollan Oct 30 '13 at 14:52
  • I change the if to @if (cartLine.Availability == "Check Availability") – Charalampos Afionis Oct 30 '13 at 15:33
  • Yes that is my bad I missed the different variable names, I will update the post. Glad it helped. – rclement Oct 30 '13 at 16:39