我在MVC3 Razor视图中使用了太多IF条件 - 如果条件比较两个或更多值,则差不多230个。问题是它在服务器上使用了太多的内存和处理器。这就是服务器响应时间非常缓慢超过6秒的原因。
我该怎么办?我应该减少使用If条件还是有其他选择?
(我也可以在这里发布我的代码)
使用代码更新:
控制器:
public ActionResult Index(string query)
{
name1 = query.Substring(0, query.IndexOf("-vs-"));
name2 = query.Substring(query.IndexOf("-vs-") + 1, query.Length - query.IndexOf("-vs-") - 1);
name2 = name2.Replace("vs-", "");
var model = _comp.GetViewModel(name1 , name2 );
}
模式:
public CpusViewModel GetViewModel(int? id1, int? id2)
{
if (id1 == null) return null;
if (id2 == null) return null;
var cpu1 = _comp.Get(p => p.cpuId == id1);
if (cpu1 == null) return null;
var cpu2 = _comp.Get(p => p.cpuId == id2);
if (cpu2 == null) return null;
return new CpusViewModel
{
CPUId1 = cpu1.cpuId,
CPUImage1 = cpu1.cpuImageName,
CPUImageFolder1 = cpu1.cpuImageName.Substring(0,1),
CpuMunafacturer1 = cpu1.cpuMunafacturer,
CpuFamily1 = cpu1.cpuFamily,
CpuModel1 = cpu1.cpuModel,
CpuQuery1 = cpu1.cpuQuery,
CpuTitle1 = cpu1.cpuQuery.Replace("-"," "),
CpuSummaryClockSpeedNodeText1 = cpu1.cpuSummaryClockSpeedNodeText,
CpuSummaryCoredNodeText1 = cpu1.cpuSummaryCoredNodeText,
CpuSummaryIsUnlockedNodeText1 = cpu1.cpuSummaryIsUnlockedNodeText,
CpuFeaturedReview1 = cpu1.cpuFeaturedReview,
CpuFeaturedReviewLinkAndDate1 = cpu1.cpuFeaturedReviewLinkAndDate,
CpusortMainBassScore1 = cpu1.cpuBossValueScoreNew,
CpuOverclockingScoreNew1 = cpu1.cpuOverclockingScoreNew,
CpuSingleCorePerformanceScoreNew1 = cpu1.cpuSingleCorePerformanceScoreNew,
CpusortBenchmarkPerformanceScoreNew1 = cpu1.cpusortBenchmarkPerformanceScoreNew,
CpuValueScoreNew1 = cpu1.cpuValueScoreNew,
CpuBenchmaKX264HD4PASS1NodeText1 = cpu1.cpuBenchmaKX264HD4PASS1NodeText,
CpuBenchmaKX264HD4PASS2NodeText1 = cpu1.cpuBenchmaKX264HD4PASS2NodeText,
CpuBenchmaCinebenchR1032BitNodeText1 = cpu1.cpuBenchmaCinebenchR1032BitNodeText,
CpuBenchmaCinebenchR1032Bit1CoreNodeText1 = cpu1.cpuBenchmaCinebenchR1032Bit1CoreNodeText,
CpuBenchmarkPerformancePerDollarNodeText1 = cpu1.cpuBenchmarkPerformancePerDollarNodeText,
CpuBenchmarkSysMark20073DNodeText1 = cpu1.cpuBenchmarkSysMark20073DNodeText,
CpuBenchmarkSysMark2007ProductivityNodeText1 = cpu1.cpuBenchmarkSysMark2007ProductivityNodeText,
CpuBenchmarkSysMark2007VideoCreationNodeText1 = cpu1.cpuBenchmarkSysMark2007VideoCreationNodeText,
CpuBenchmarkCinebenchR11_5NodeText1 = cpu1.cpuBenchmarkCinebenchR11_5NodeText,
CpuBenchmarkCinebenchR11_5_SingleNodeText1 = cpu1.cpuBenchmarkCinebenchR11_5_SingleNodeText,
CpuBenchmark3DMark06CPUNodeText1 = cpu1.cpuBenchmark3DMark06CPUNodeText,
CpuBenchmark3DMark11PhysicsNodeText1 = cpu1.cpuBenchmark3DMark11PhysicsNodeText,
CpuBenchmarkPassMarkNodeText1 = cpu1.cpuBenchmarkPassMarkNodeText,
CpuBenchmarkPassMarkSingleCoreNodeText1 = cpu1.cpuBenchmarkPassMarkSingleCoreNodeText,
CpuBenchmarkGeekBenchNodeText1 = cpu1.cpuBenchmarkGeekBenchNodeText,
CpuBenchmarkX264HD4NodeText1 = cpu1.cpuBenchmarkX264HD4NodeText,
CpuBenchmarSysMark2007OverallNodeText1 = cpu1.cpuBenchmarSysMark2007OverallNodeText,
CpuGeneralCodeNameNodeText1 = cpu1.cpuGeneralCodeNameNodeText,
CpuGeneralMarketNodeText1 = cpu1.cpuGeneralMarketNodeText,
CpuGeneralManuProductPageNodeText1 = cpu1.cpuGeneralManuProductPageNodeText,
CpuSummaryTurboClockSpeedNodeText1 = cpu1.cpuSummaryTurboClockSpeedNodeText,
CpuSummarySocketTypeNodeText1 = cpu1.cpuSummarySocketTypeNodeText,
CpuSummaryIsHyperthreadedNodeText1 = cpu1.cpuSummaryIsHyperthreadedNodeText,
CpuDetailsArchitectureNodeText1 = cpu1.cpuDetailsArchitectureNodeText,
CpuDetailsThreadsNodeText1 = cpu1.cpuDetailsThreadsNodeText,
CpuDetailsL2CacheNodeText1 = cpu1.cpuDetailsL2CacheNodeText,
CpuDetailsL2CachePerCoreNodeText1 = cpu1.cpuDetailsL2CachePerCoreNodeText,
CpuDetailsL3CacheNodeText1 = cpu1.cpuDetailsL3CacheNodeText,
CpuDetailsL3CachePerCoreNodeText1 = cpu1.cpuDetailsL3CachePerCoreNodeText,
CpuDetailsManufactureProcessNodeText1 = cpu1.cpuDetailsManufactureProcessNodeText,
CpuDetailsTransistorCountNodeText1 = cpu1.cpuDetailsTransistorCountNodeText,
CpuDetailsMaxCPUsNodeText1 = cpu1.cpuDetailsMaxCPUsNodeText,
CpuDetailsClockMultiplierNodeText1 = cpu1.cpuDetailsClockMultiplierNodeText,
CpuDetailsVoltageRangeNodeText1 = cpu1.cpuDetailsVoltageRangeNodeText,
CpuDetailsOperatingTempNodeText1 = cpu1.cpuDetailsOperatingTempNodeText,
CpuFeaturesNXBitNodeText1 = cpu1.cpuFeaturesNXBitNodeText,
CpuFeaturesTrustedComputingNodeText1 = cpu1.cpuFeaturesTrustedComputingNodeText,
CpuFeaturesVirtualizationSupportNodeText1 = cpu1.cpuFeaturesVirtualizationSupportNodeText,
CpuFeaturesInstructionSetExtensionsNodeText1 = cpu1.cpuFeaturesInstructionSetExtensionsNodeText,
CpuFeaturesDynamicFrequencyScalingNodeText1 = cpu1.cpuFeaturesDynamicFrequencyScalingNodeText,
CpuOverclockingOverclockPopulartyNodeText1 = cpu1.cpuOverclockingOverclockPopulartyNodeText,
CpuOverclockingOverclockReviewScoreNodeText1 = cpu1.cpuOverclockingOverclockReviewScoreNodeText,
CpuOverclockingOverclockedClockSpeedNodeText1 = cpu1.cpuOverclockingOverclockedClockSpeedNodeText,
CpuOverclockingOverclockedClockSpeedWaterNodeText1 = cpu1.cpuOverclockingOverclockedClockSpeedWaterNodeText,
CpuOverclockingPassmarkOverclockedNodeText1 = cpu1.cpuOverclockingPassmarkOverclockedNodeText,
CpuOverclockingOverclockedClockSpeedAirNodeText1 = cpu1.cpuOverclockingOverclockedClockSpeedAirNodeText,
CpuGPUGpuNodeText1 = cpu1.cpuGPUGpuNodeText,
CpuGPULabelNodeText1 = cpu1.cpuGPULabelNodeText,
CpuGPULatestDirectXNodeText1 = cpu1.cpuGPULatestDirectXNodeText,
CpuGPUNumberDisplaysSupportedNodeText1 = cpu1.cpuGPUNumberDisplaysSupportedNodeText,
CpuGPUClockSpeedNodeText1 = cpu1.cpuGPUClockSpeedNodeText,
CpuGPUTurboClockSpeedNodeText1 = cpu1.cpuGPUTurboClockSpeedNodeText,
CpuGPU3DMark06NodeText1 = cpu1.cpuGPU3DMark06NodeText,
CpuPowerTDPNodeText1 = cpu1.cpuPowerTDPNodeText,
CpuPowerAnnualHomeEnergyCostNodeText1 = cpu1.cpuPowerAnnualHomeEnergyCostNodeText,
CpuPowerAnnualCommercialEnergyCostNodeText1 = cpu1.cpuPowerAnnualCommercialEnergyCostNodeText,
CpuPowerPerformancePerWattNodeText1 = cpu1.cpuPowerPerformancePerWattNodeText,
CpuPowerIdlePowerConsumptionNodeText1 = cpu1.cpuPowerIdlePowerConsumptionNodeText,
CpuPowerPeakPowerConsumptionNodeText1 = cpu1.cpuPowerPeakPowerConsumptionNodeText,
CpuPowerTypicalPowerConsumptionNodeText1 = cpu1.cpuPowerTypicalPowerConsumptionNodeText,
CpuMemoryControllerNodeText1 = cpu1.cpuMemoryControllerNodeText,
CpuMemoryTypeNodeText1 = cpu1.cpuMemoryTypeNodeText,
CpuMemoryContollerChannelsNodeText1 = cpu1.cpuMemoryContollerChannelsNodeText,
CpuMemorySupportsECCNodeText1 = cpu1.cpuMemorySupportsECCNodeText,
CpuMemoryMaximumBandwidthNodeText1 = cpu1.cpuMemoryMaximumBandwidthNodeText,
CpuMemoryMaximumMemorySizeNodeText1 = cpu1.cpuMemoryMaximumMemorySizeNodeText,
CpuBusArchitectureNodeText1 = cpu1.cpuBusArchitectureNodeText,
CpuBusNumberOfLinksNodeText1 = cpu1.cpuBusNumberOfLinksNodeText,
CpuBusTransferRateNodeText1 = cpu1.cpuBusTransferRateNodeText,
CpuBusDataRateNodeText1 = cpu1.cpuBusDataRateNodeText,
CpuBusClockSpeedNodeText1 = cpu1.cpuBusClockSpeedNodeText,
CpuMobileBenchmarkglbenchmark_2_1_egypt_offscreenNodeText1 = cpu1.cpuMobileBenchmarkglbenchmark_2_1_egypt_offscreenNodeText,
CpuMobileBenchmarkprop_glbenchmark_2_5_egypt_classic_offscreenNodeText1 = cpu1.cpuMobileBenchmarkprop_glbenchmark_2_5_egypt_classic_offscreenNodeText,
CpuMobileBenchmarkprop_sunspider_0_9_1NodeText1 = cpu1.cpuMobileBenchmarkprop_sunspider_0_9_1NodeText,
CpuMobileBenchmarkprop_browsermarkNodeText1 = cpu1.cpuMobileBenchmarkprop_browsermarkNodeText,
CpuMobileBenchmarkprop_browsermark_2NodeText1 = cpu1.cpuMobileBenchmarkprop_browsermark_2NodeText,
CpuGeneralAnnoucedDateNodeTextSmall1 = cpu1.cpuGeneralAnnoucedDateNodeTextSmall,
CpuGeneralExpectedDateNodeTextSmall1 = cpu1.cpuGeneralExpectedDateNodeTextSmall,
CpuGeneralRleasedDateNodeTextSmall1 = cpu1.cpuGeneralRleasedDateNodeTextSmall,
CpuGeneralAnnoucedDateNodeText1 = cpu1.cpuGeneralAnnoucedDateNodeText,
CpuGeneralRleasedDateNodeText1 = cpu1.cpuGeneralRleasedDateNodeText,
CpuGeneralExpectedDateNodeText1 = cpu1.cpuGeneralExpectedDateNodeText,
CPUId2 = cpu2.cpuId,
CPUImage2 = cpu2.cpuImageName,
CPUImageFolder2 = cpu2.cpuImageName.Substring(0, 1),
CpuMunafacturer2 = cpu2.cpuMunafacturer,
CpuFamily2 = cpu2.cpuFamily,
CpuModel2 = cpu2.cpuModel,
CpuQuery2 = cpu2.cpuQuery,
CpuTitle2 = cpu2.cpuQuery.Replace("-", " "),
CpuSummaryClockSpeedNodeText2 = cpu2.cpuSummaryClockSpeedNodeText,
CpuSummaryCoredNodeText2 = cpu2.cpuSummaryCoredNodeText,
CpuSummaryIsUnlockedNodeText2 = cpu2.cpuSummaryIsUnlockedNodeText,
CpuFeaturedReview2 = cpu2.cpuFeaturedReview,
CpuFeaturedReviewLinkAndDate2 = cpu2.cpuFeaturedReviewLinkAndDate,
CpusortMainBassScore2 = cpu2.cpuBossValueScoreNew,
CpuOverclockingScoreNew2 = cpu2.cpuOverclockingScoreNew,
CpuSingleCorePerformanceScoreNew2 = cpu2.cpuSingleCorePerformanceScoreNew,
CpusortBenchmarkPerformanceScoreNew2 = cpu2.cpusortBenchmarkPerformanceScoreNew,
CpuValueScoreNew2 = cpu2.cpuValueScoreNew,
CpuBenchmaKX264HD4PASS1NodeText2 = cpu2.cpuBenchmaKX264HD4PASS1NodeText,
CpuBenchmaKX264HD4PASS2NodeText2 = cpu2.cpuBenchmaKX264HD4PASS2NodeText,
CpuBenchmaCinebenchR1032BitNodeText2 = cpu2.cpuBenchmaCinebenchR1032BitNodeText,
CpuBenchmaCinebenchR1032Bit1CoreNodeText2 = cpu2.cpuBenchmaCinebenchR1032Bit1CoreNodeText,
CpuBenchmarkPerformancePerDollarNodeText2 = cpu2.cpuBenchmarkPerformancePerDollarNodeText,
CpuBenchmarkSysMark20073DNodeText2 = cpu2.cpuBenchmarkSysMark20073DNodeText,
CpuBenchmarkSysMark2007ProductivityNodeText2 = cpu2.cpuBenchmarkSysMark2007ProductivityNodeText,
CpuBenchmarkSysMark2007VideoCreationNodeText2 = cpu2.cpuBenchmarkSysMark2007VideoCreationNodeText,
CpuBenchmarkCinebenchR11_5NodeText2 = cpu2.cpuBenchmarkCinebenchR11_5NodeText,
CpuBenchmarkCinebenchR11_5_SingleNodeText2 = cpu2.cpuBenchmarkCinebenchR11_5_SingleNodeText,
CpuBenchmark3DMark06CPUNodeText2 = cpu2.cpuBenchmark3DMark06CPUNodeText,
CpuBenchmark3DMark11PhysicsNodeText2 = cpu2.cpuBenchmark3DMark11PhysicsNodeText,
CpuBenchmarkPassMarkNodeText2 = cpu2.cpuBenchmarkPassMarkNodeText,
CpuBenchmarkPassMarkSingleCoreNodeText2 = cpu2.cpuBenchmarkPassMarkSingleCoreNodeText,
CpuBenchmarkGeekBenchNodeText2 = cpu2.cpuBenchmarkGeekBenchNodeText,
CpuBenchmarkX264HD4NodeText2 = cpu2.cpuBenchmarkX264HD4NodeText,
CpuBenchmarSysMark2007OverallNodeText2 = cpu2.cpuBenchmarSysMark2007OverallNodeText,
CpuGeneralCodeNameNodeText2 = cpu2.cpuGeneralCodeNameNodeText,
CpuGeneralMarketNodeText2 = cpu2.cpuGeneralMarketNodeText,
CpuGeneralManuProductPageNodeText2 = cpu2.cpuGeneralManuProductPageNodeText,
CpuSummaryTurboClockSpeedNodeText2 = cpu2.cpuSummaryTurboClockSpeedNodeText,
CpuSummarySocketTypeNodeText2 = cpu2.cpuSummarySocketTypeNodeText,
CpuSummaryIsHyperthreadedNodeText2 = cpu2.cpuSummaryIsHyperthreadedNodeText,
CpuDetailsArchitectureNodeText2 = cpu2.cpuDetailsArchitectureNodeText,
CpuDetailsThreadsNodeText2 = cpu2.cpuDetailsThreadsNodeText,
CpuDetailsL2CacheNodeText2 = cpu2.cpuDetailsL2CacheNodeText,
CpuDetailsL2CachePerCoreNodeText2 = cpu2.cpuDetailsL2CachePerCoreNodeText,
CpuDetailsL3CacheNodeText2 = cpu2.cpuDetailsL3CacheNodeText,
CpuDetailsL3CachePerCoreNodeText2 = cpu2.cpuDetailsL3CachePerCoreNodeText,
CpuDetailsManufactureProcessNodeText2 = cpu2.cpuDetailsManufactureProcessNodeText,
CpuDetailsTransistorCountNodeText2 = cpu2.cpuDetailsTransistorCountNodeText,
CpuDetailsMaxCPUsNodeText2 = cpu2.cpuDetailsMaxCPUsNodeText,
CpuDetailsClockMultiplierNodeText2 = cpu2.cpuDetailsClockMultiplierNodeText,
CpuDetailsVoltageRangeNodeText2 = cpu2.cpuDetailsVoltageRangeNodeText,
CpuDetailsOperatingTempNodeText2 = cpu2.cpuDetailsOperatingTempNodeText,
CpuFeaturesNXBitNodeText2 = cpu2.cpuFeaturesNXBitNodeText,
CpuFeaturesTrustedComputingNodeText2 = cpu2.cpuFeaturesTrustedComputingNodeText,
CpuFeaturesVirtualizationSupportNodeText2 = cpu2.cpuFeaturesVirtualizationSupportNodeText,
CpuFeaturesInstructionSetExtensionsNodeText2 = cpu2.cpuFeaturesInstructionSetExtensionsNodeText,
CpuFeaturesDynamicFrequencyScalingNodeText2 = cpu2.cpuFeaturesDynamicFrequencyScalingNodeText,
CpuOverclockingOverclockPopulartyNodeText2 = cpu2.cpuOverclockingOverclockPopulartyNodeText,
CpuOverclockingOverclockReviewScoreNodeText2 = cpu2.cpuOverclockingOverclockReviewScoreNodeText,
CpuOverclockingOverclockedClockSpeedNodeText2 = cpu2.cpuOverclockingOverclockedClockSpeedNodeText,
CpuOverclockingOverclockedClockSpeedWaterNodeText2 = cpu2.cpuOverclockingOverclockedClockSpeedWaterNodeText,
CpuOverclockingPassmarkOverclockedNodeText2 = cpu2.cpuOverclockingPassmarkOverclockedNodeText,
CpuOverclockingOverclockedClockSpeedAirNodeText2 = cpu2.cpuOverclockingOverclockedClockSpeedAirNodeText,
CpuGPUGpuNodeText2 = cpu2.cpuGPUGpuNodeText,
CpuGPULabelNodeText2 = cpu2.cpuGPULabelNodeText,
CpuGPULatestDirectXNodeText2 = cpu2.cpuGPULatestDirectXNodeText,
CpuGPUNumberDisplaysSupportedNodeText2 = cpu2.cpuGPUNumberDisplaysSupportedNodeText,
CpuGPUClockSpeedNodeText2 = cpu2.cpuGPUClockSpeedNodeText,
CpuGPUTurboClockSpeedNodeText2 = cpu2.cpuGPUTurboClockSpeedNodeText,
CpuGPU3DMark06NodeText2 = cpu2.cpuGPU3DMark06NodeText,
CpuPowerTDPNodeText2 = cpu2.cpuPowerTDPNodeText,
CpuPowerAnnualHomeEnergyCostNodeText2 = cpu2.cpuPowerAnnualHomeEnergyCostNodeText,
CpuPowerAnnualCommercialEnergyCostNodeText2 = cpu2.cpuPowerAnnualCommercialEnergyCostNodeText,
CpuPowerPerformancePerWattNodeText2 = cpu2.cpuPowerPerformancePerWattNodeText,
CpuPowerIdlePowerConsumptionNodeText2 = cpu2.cpuPowerIdlePowerConsumptionNodeText,
CpuPowerPeakPowerConsumptionNodeText2 = cpu2.cpuPowerPeakPowerConsumptionNodeText,
CpuPowerTypicalPowerConsumptionNodeText2 = cpu2.cpuPowerTypicalPowerConsumptionNodeText,
CpuMemoryControllerNodeText2 = cpu2.cpuMemoryControllerNodeText,
CpuMemoryTypeNodeText2 = cpu2.cpuMemoryTypeNodeText,
CpuMemoryContollerChannelsNodeText2 = cpu2.cpuMemoryContollerChannelsNodeText,
CpuMemorySupportsECCNodeText2 = cpu2.cpuMemorySupportsECCNodeText,
CpuMemoryMaximumBandwidthNodeText2 = cpu2.cpuMemoryMaximumBandwidthNodeText,
CpuMemoryMaximumMemorySizeNodeText2 = cpu2.cpuMemoryMaximumMemorySizeNodeText,
CpuBusArchitectureNodeText2 = cpu2.cpuBusArchitectureNodeText,
CpuBusNumberOfLinksNodeText2 = cpu2.cpuBusNumberOfLinksNodeText,
CpuBusTransferRateNodeText2 = cpu2.cpuBusTransferRateNodeText,
CpuBusDataRateNodeText2 = cpu2.cpuBusDataRateNodeText,
CpuBusClockSpeedNodeText2 = cpu2.cpuBusClockSpeedNodeText,
CpuMobileBenchmarkglbenchmark_2_1_egypt_offscreenNodeText2 = cpu2.cpuMobileBenchmarkglbenchmark_2_1_egypt_offscreenNodeText,
CpuMobileBenchmarkprop_glbenchmark_2_5_egypt_classic_offscreenNodeText2 = cpu2.cpuMobileBenchmarkprop_glbenchmark_2_5_egypt_classic_offscreenNodeText,
CpuMobileBenchmarkprop_sunspider_0_9_1NodeText2 = cpu2.cpuMobileBenchmarkprop_sunspider_0_9_1NodeText,
CpuMobileBenchmarkprop_browsermarkNodeText2 = cpu2.cpuMobileBenchmarkprop_browsermarkNodeText,
CpuMobileBenchmarkprop_browsermark_2NodeText2 = cpu2.cpuMobileBenchmarkprop_browsermark_2NodeText,
CpuGeneralAnnoucedDateNodeTextSmall2 = cpu2.cpuGeneralAnnoucedDateNodeTextSmall,
CpuGeneralExpectedDateNodeTextSmall2 = cpu2.cpuGeneralExpectedDateNodeTextSmall,
CpuGeneralRleasedDateNodeTextSmall2 = cpu2.cpuGeneralRleasedDateNodeTextSmall,
CpuGeneralAnnoucedDateNodeText2 = cpu2.cpuGeneralAnnoucedDateNodeText,
CpuGeneralRleasedDateNodeText2 = cpu2.cpuGeneralRleasedDateNodeText,
CpuGeneralExpectedDateNodeText2 = cpu2.cpuGeneralExpectedDateNodeText
};
}
查看(使用这样的值):
@{
if (Model.CpuGeneralRleasedDateNodeTextSmall1 != null)
{
if ((DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall1)).TotalDays < 31.0)
{
@("Released ") @Model.CpuGeneralRleasedDateNodeText1; <span class="justreleasedbadge">@("Just Released")</span>
}
else if ((DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall1)).TotalDays > 31.0 && (DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall1)).TotalDays < 120.0)
{
@("Released ") @Model.CpuGeneralRleasedDateNodeText1; <span class="newbadge">@("New")</span>
}
else if ((DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall1)).TotalDays > 120.0 && (DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall1)).TotalDays < 365.0)
{
@("Released ") @Model.CpuGeneralRleasedDateNodeText1;
}
else if ((DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall1)).TotalDays > 365.0)
{
@("Released ") @Model.CpuGeneralRleasedDateNodeText1; <span class="olderbadge">@("Older")</span>
}
}
else if (Model.CpuGeneralAnnoucedDateNodeTextSmall1 != null && Model.CpuGeneralRleasedDateNodeTextSmall1 == null)
{
@Model.CpuGeneralAnnoucedDateNodeText1; <span class="comingsoonbadge">@("Coming Soon")</span> @("Annouced ")
}
else if (Model.CpuGeneralExpectedDateNodeTextSmall1 != null && Model.CpuGeneralRleasedDateNodeTextSmall1 == null && Model.CpuGeneralAnnoucedDateNodeTextSmall1 == null)
{
@("First seen on ") @Model.CpuGeneralExpectedDateNodeText1; <span class="rumoredbadge">@("Rumored")</span>
}
}
</span>
</div>
<div class="comparelinkTitle"><a href="@Url.Content("~/Cpu/" + @Model.CpuQuery1)"><span style="font-size:20px;">@Model.CpuMunafacturer1 @Model.CpuFamily1 @Model.CpuModel1</span></a></div>
<div class="h1small2">
@Math.Round(Convert.ToDecimal(Model.CpuSummaryClockSpeedNodeText1), 1) GHz
@{
if (Model.CpuSummaryCoredNodeText1 != "Unknown")
{
@("| "); @Model.CpuSummaryCoredNodeText1;
}
}
@{
if (Model.CpuSummaryIsUnlockedNodeText1 != "Unknown")
{
if (Model.CpuSummaryIsUnlockedNodeText1 == "Yes")
{
@(" | Unlocked");
}
else
{
@("");
}
}
}
</div>
<div id="pnlContainer" style="text-align:right">
<a href="@Url.Content("~/Cpu/" + @Model.CpuQuery1)"><img alt="@Model.CpuMunafacturer1 @Model.CpuFamily1 @Model.CpuModel1" class="imgclass3" style="max-width:370px" src="http://img.cpusort.com/@Model.CPUImageFolder1/@Model.CPUImage1" /></a>
@if (Model.CpusortMainBassScore1 != 0 && Model.CpusortMainBassScore2 != 0 && Model.CpuGeneralMarketNodeText1 != "Mobile" && Model.CpuGeneralMarketNodeText2 != "Mobile")
{
<div class="dragDiv" style="right:0px" id="dragDiv">
<span class="scoretextsmall">@Math.Round(Convert.ToDecimal(Model.CpusortMainBassScore1), 1)</span>
<span class="scoreunits" style="color:#fff">Out of 10</span>
</div>
}
else if (Model.CpusortMainBassScore1 != 0 && Model.CpusortMainBassScore2 != 0 && Model.CpuGeneralMarketNodeText1 == "Mobile" && Model.CpuGeneralMarketNodeText2 == "Mobile")
{
<div class="dragDiv" style="right:0px" id="dragDiv">
<span class="scoretextsmall">@Math.Round(Convert.ToDecimal(Model.CpusortMainBassScore1), 1)</span>
<span class="scoreunits" style="color:#fff">Out of 10</span>
</div>
}
</div>
@if (Model.CpuFeaturedReview1 != null)
{
<blockquote>@Model.CpuFeaturedReview1</blockquote>
<span style="padding-left:18px;">@Html.Raw(Model.CpuFeaturedReviewLinkAndDate1)</span>
}
</td>
<td style="width:50%; padding:0px 0px 10px 20px; text-align:left;">
<div style="float:right">
<span class="comparesmall" style="vertical-align:middle" >
@{
if (Model.CpuGeneralRleasedDateNodeTextSmall2 != null)
{
if ((DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall2)).TotalDays < 31.0)
{
<span class="justreleasedbadge">@("Just Released")</span> @("Released") @Model.CpuGeneralRleasedDateNodeText2;
}
else if ((DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall2)).TotalDays > 31.0 && (DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall2)).TotalDays < 120.0)
{
<span class="newbadge">@("New")</span> @("Released ") @Model.CpuGeneralRleasedDateNodeText2;
}
else if ((DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall2)).TotalDays > 120.0 && (DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall2)).TotalDays < 365.0)
{
@("Released ") @Model.CpuGeneralRleasedDateNodeText2;
}
else if ((DateTime.UtcNow - Convert.ToDateTime(Model.CpuGeneralRleasedDateNodeTextSmall2)).TotalDays > 365.0)
{
<span class="olderbadge">@("Older")</span> @("Released ") @Model.CpuGeneralRleasedDateNodeText2;
}
}
else if (Model.CpuGeneralAnnoucedDateNodeTextSmall2 != null && Model.CpuGeneralRleasedDateNodeTextSmall2 == null)
{
<span class="comingsoonbadge">@("Coming Soon")</span> @("Annouced ") @Model.CpuGeneralAnnoucedDateNodeText2;
}
else if (Model.CpuGeneralExpectedDateNodeTextSmall2 != null && Model.CpuGeneralRleasedDateNodeTextSmall2 == null && Model.CpuGeneralAnnoucedDateNodeTextSmall2 == null)
{
<span class="rumoredbadge">@("Rumored")</span> @("First seen on ") @Model.CpuGeneralExpectedDateNodeText2;
}
}
</span>
</div>
<div class="comparelinkTitle"><a href="@Url.Content("~/Cpu/" + @Model.CpuQuery2)"><span style="font-size:20px; line-height:22px">@Model.CpuMunafacturer2 @Model.CpuFamily2 @Model.CpuModel2</span></a></div>
<div class="h1small2">
@Math.Round(Convert.ToDecimal(Model.CpuSummaryClockSpeedNodeText2), 1) GHz
@{
if (Model.CpuSummaryCoredNodeText2 != "Unknown")
{
@("| "); @Model.CpuSummaryCoredNodeText2;
}
}
@{
if (Model.CpuSummaryIsUnlockedNodeText2 != "Unknown")
{
if (Model.CpuSummaryIsUnlockedNodeText2 == "Yes")
{
@(" | Unlocked");
}
else
{
@("");
}
}
}
</div>
<div id="pnlContainer" style="text-align:left">
<a href="@Url.Content("~/Cpu/" + @Model.CpuQuery2)"><img alt="@Model.CpuMunafacturer2 @Model.CpuFamily2 @Model.CpuModel2" class="imgclass2" style="max-width:370px" src="http://img.cpusort.com/@Model.CPUImageFolder2/@Model.CPUImage2" /></a>
@if (Model.CpusortMainBassScore1 != 0 && Model.CpusortMainBassScore2 != 0 && Model.CpuGeneralMarketNodeText1 != "Mobile" && Model.CpuGeneralMarketNodeText2 != "Mobile")
{
<div class="dragDiv" style="left:0px" id="dragDiv">
<span class="scoretextsmall">@Math.Round(Convert.ToDecimal(Model.CpusortMainBassScore2), 1)</span>
<span class="scoreunits" style="color:#fff">Out of 10</span>
</div>
}
else if (Model.CpusortMainBassScore1 != 0 && Model.CpusortMainBassScore2 != 0 && Model.CpuGeneralMarketNodeText1 == "Mobile" && Model.CpuGeneralMarketNodeText2 == "Mobile")
{
<div class="dragDiv" style="left:0px" id="dragDiv">
<span class="scoretextsmall">@Math.Round(Convert.ToDecimal(Model.CpusortMainBassScore2), 1)</span>
<span class="scoreunits" style="color:#fff">Out of 10</span>
</div>
}
</div>
@if (Model.CpuFeaturedReview2 != null)
{
<blockquote>@Model.CpuFeaturedReview2</blockquote>
<span style="padding-left:18px;">@Html.Raw(Model.CpuFeaturedReviewLinkAndDate2)</span>
}
</td>
}
答案 0 :(得分:5)
为什么,为什么你的VIEW中有这么多的支票? MVC是关于数据,逻辑和您向用户展示的事物的分离。我很确定通过让控制器处理这些if语句可以避免很多这些if语句。控制器处理完这些后,应将干净的数据结果传递给视图。这将大大提高性能!