मुझे कोई समस्या है जहां नियंत्रक कार्रवाई को कम से कम दो बार बुलाया जाता है। मेरे पास एक दृश्य है जिसमें इसके लेआउट पेज के रूप में एक और दृश्य है, और दृश्य को कई बार कहा जाता है। यदि मैं लेआउट के लिए विनिर्देश को हटा देता हूं तो कार्रवाई को लगातार एक बार निष्पादित किया जाता है। मैंने स्टैक ओवरफ्लो और अन्य साइटों को देखा लेकिन मुझे ऐसी समस्या नहीं मिली जो मेरे जैसी ही विशेषताएं थी इसलिए मैं एक नया प्रश्न पोस्ट कर रहा हूं।एमवीसी कंट्रोलर एक्शन कई बार कॉल किया जाता है जब लेआउट निर्दिष्ट किया जाता है
_ViewStart.cshtml:
@{
Layout = "~/Views/Shared/_ProfileLayout.cshtml";
}
Index.cshtml inside my Profile folder: @{
ViewBag.Title = "Index";
}
Index
Controller Action:
public ActionResult Index()
{
//ToDo: BusinessLogic
//This method gets called twice
//******************//
return View();
}
ऐसा लगता है कि यह एक साधारण समस्या है और मुझे निश्चित रूप से कुछ स्पष्ट याद आ रही है। मैंने इस साइट पर नमूना प्रोजेक्ट पोस्ट किया है: https://skydrive.live.com/#cid=F2DAB940147490B0&id=F2DAB940147490B0%21140
कोई भी विचार क्या गलत है?
धन्यवाद
अद्यतन: यहाँ दृश्य है: @ { ViewBag.Title = "TestMVCProject"; लेआउट = शून्य;
<div class="footer">
<div class="fltrt">Copyright 2012 TestMVCProject Inc </div>
<p><a href="/Profile/Test">About</a> | <a href="#">Contact</a> | <a href="#">FAQ</a> | <a href="#">Advertise</a> | <a href="#">Support</a> | <a href="#">Feedback</a> | <a href="#">Login</a> | <a href="#">Register</a> | <a href="#">Privacy</a> | <a href="#">Terms</a></p>
</div>
अपडेट:: @Tieson टी: धन्यवाद, मैं इस RenderPage के बजाय Html.Partial में परिवर्तित हो }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TestMVCProject</title>
<link rel="Stylesheet" type="text/css" href="../../Content/ActiveSite.css" />
<link href="../../Content/themes/TestMVCProject/jquery-ui-1.9.1.custom.min.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.8.2.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.9.1.custom.js" type="text/javascript"></script>
</head>
<body>
<div class="container">
<div class="header">
<div id="loginimagecontainer">
@using (Html.BeginForm("LoginActions", "Account", FormMethod.Post, new { @id = "LoginActionsForm" }))
{
@Html.AntiForgeryToken()
<a href="#"><img src="/images/icons/message-icon.png" width="60" height="60" alt="Messages" title="Messages"/></a>
<a href="/Account/LogOff"><img src="/images/icons/log-out-icon.png" width="60" height="60" alt="Log off" title="Log off"/></a>
}
</div>
<div class="logotext"><img alt="TestMVCProject Logo" src="#" width="350" height="150" id="TestMVCProjectLogo" /></div>
</div>
<div class="content profile">
<div id="leftPane">
<img src="#" alt="Placeholder" width="165" height="200" id="ProfilePhoto" title="Profile Photo" />
<div id="Username"></div>
<div id="NavLinks">
<div class="ProfileNavigation" onclick="Navigate('/Profile/Update')"><span>Profile</span><img src="/images/icons/edit-icon.png" width="30" height="30" alt="Profile" /></div>
<div class="ProfileNavigation"><span>Search</span><img src="/images/icons/search-icon.png" width="30" height="30" alt="Search" /></div>
<div class="ProfileNavigation" onclick="Navigate('/Photo')"><span>Photos</span><img src="/images/icons/camera-icon.png" width="30" height="30" alt="Photos"/></div>
</div>
</div>
<div id="adcontainer">
<h4>Ads go here</h4>
<p>content goes here</p>
</div>
<div id="centerPane">
@RenderBody()
</div>
</div>
@RenderPage("~/Views/Shared/_Footer.cshtml")
<div id="redirectiondialog" class="dialog">
<br />
Hey, wait up... we're redirecting you over to the login page
<br />
</div>
<script type="text/javascript">
function Navigate(url) {
window.location = url;
return false;
}
</script>
</div>
</body>
</html>
और यहाँ पाद लेख पृष्ठ है। हालांकि समस्या अभी भी बनी हुई है क्योंकि एक्शन विधि को अभी भी दो बार बुलाया जाता है ... (संपादन विवरण क्योंकि मेरे पास टिप्पणियां जोड़ने के लिए विशेषाधिकार नहीं हैं)
अपना लेआउट व्यू कैसा दिखता है? –
मैंने अभी विवरण को अपडेट किया है और अब यह जानकारी जोड़ा है – user1717575