本文介绍了我有一个MVC应用程序示例,但有一部分我不明白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个应用程序是一个电子商店的应用程序。您可以选择产品。



有一个我不明白的代码:

< div class =col-md-3 > 
< div class =categorywrap>
< a href =〜/ Views / StoreFront / Index / 1>
< h2> Dairy< / h2>
< img src =〜/ Content / Images / dairy.pngalt =>
< / a>
< / div>
< / div>
< div class =col-md-3>
< div class =categorywrap>
< a href =〜/ Views / StoreFront / Index / 2>
< h2>肉类< / h2>
< img src =〜/ Content / Images / meat.pngalt =/>
< / a>



< div class =categorywrap> 
< a href =〜/ Views / StoreFront / Index / 3>
< h2> Bakery< / h2>
< img src =〜/ Content / Images / bakery.pngalt =/>

< / a>
< / div>



这是StoreFront / Index视图:

 @model Models.Category 

@ {
ViewBag.Title = Model.Name;
}
< br />
< br />
< div class =row>
< div class =col-xs-12 col-md-3>
< ul class =nav nav-pills nav-stacked>
@if(Model.Name ==Dairy)
{
< li class =active>
< a href =〜/ Views / StoreFront / Index.cshtml / 1> DAIRY< / a>
< / li>
}其他
{
< li>
< a href =〜/ Views / StoreFront / Index.cshtml / 1> DAIRY< / a>
< / li>
}
@if(Model.Name ==Meats)
{
< li class =active>
< a href =〜/ Views / StoreFront / Index.cshtml / 2> MEATS< / a>
< / li>
}
其他
{
< li>
< a href =〜/ Views / StoreFront / Index.cshtml / 2> MEATS< / a>
< / li>
}
@if(Model.Name ==Bakery)
{
< li class =active>
< a href =〜/ Views / StoreFront / Index.cshtml / 3> BAKERY< / a>
< / li>
}
其他
{
< li>
< a href =〜/ Views / StoreFront / Index.cshtml / 3> BAKERY< / a>
< / li>
}
@if(Model.Name ==Fruits)
{
< li class =active>
< a href =〜/ Views / StoreFront / Index.cshtml / 4> FRUIT& VEG< / A>
< / li>
}
其他
{
< li>
< a href =〜/ Views / StoreFront / Index.cshtml / 4> FRUITS& VEG< / A>
< / li>
}
< / ul>
< / div>
< div class =col-xs-12 col-md-9>
< div class =row>
@foreach(Model.products中的var产品)
{
< div class =col-xs-12 col-md-3>
< div class =thumbnail>
< img class =img-responsivesrc =〜/ Content / Images / Prod / @(product.Name).png/>
< div class =caption text-center>
< p>
名称:< span> @ product.Name< / span>
< / p>
< p>
价格:< span> @ product.price $< / span>
< / p>
< p class =text-center>
@ Html.ActionLink(添加到购物车,AddToCart,新{id = product.ID},新{@ class =btn btn-info})
< / p>
< / div>
< / div>
< / div>
}
< / div>
< / div>
< / div>





我尝试过:



此代码< pre>< a href =〜/ Views / StoreFront / Index / 3> 



指的是例如index / 3,而我们在StoreFront视图文件夹中只有索引视图(一个视图)!每种产品都没有3或2或1的视图。为什么?它似乎在运行时生成页面。

谢谢

解决方案




这篇关于我有一个MVC应用程序示例,但有一部分我不明白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:59