2012-09-06 11 views
9

मैं यह पता लगाने की कोशिश कर रहा हूं कि किसी सेक्शन में शामिल होना संभव है या नहीं।एएसपी.नेट एमवीसी 3: अनुभागों में शामिल करें

_Layout.cshtml

<!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" xml:lang="en"> 
<head> 
<link href="@Url.Content("~/Content/style.css")" rel="stylesheet" type="text/css" /> 
@RenderSection("Css", false) 
<script type="text/javascript" src="@Url.Content("~/Content/scripts/head.load.min.js")"></script> 
</head> 
<body class="bg_g"> 
    @RenderBody() 
    <script type="text/javascript"> 
     @RenderSection("Javascript", false) 
    </script> 
</body> 
</html> 

Logon.cshtml

@{ 
    Layout = "~/Views/Shared/_DMZ.cshtml"; 
    ViewBag.Title = "Logon"; 
} 

@section Javascript += { 
    // JAVASCRIPT CODE; 
} 

<div> 
    Stuff 
    @{ Html.RenderAction("Register", "Account"); } 
    @{ Html.RenderAction("Register2", "Account"); } 
</div> 

Register.cshtml

@{ 
    Layout = null; 
} 

@section Javascript += { 
    // More javascript code 
} 

<div> 
    Register stuff 
</div> 

Register2.cshtml

@{ 
    Layout = null; 
} 

@section Javascript += { 
    // Even More javascript code 
} 

<div> 
    Register stuff part 2 
</div> 
: यहाँ मेरी संरचना है

उम्मीद है कि यह बताता है कि मैं वास्तव में क्या करने की कोशिश कर रहा हूं। मैं अपने सीएसएस अनुभाग के साथ भी वही काम करना चाहूंगा। यह और भी बेहतर हो सकता है अगर मैं भी इसे इस तरह जावास्क्रिप्ट रेंडर करने के लिए मिल सकता है:

head.js(
    "@Url.Content("~/Content/scripts/jquery-1.6.2.min.js")", 
    "@Url.Content("~/Content/scripts/jquery.tools.min.js")", 
    "@Url.Content("~/Content/lib/jquery-validation/jquery.validate.js")", 
// Loop through all javascript files included from the sub views and add them just like above 
function() { 
    loginTabs.init(); 
    // Loop through all javascript functions that have been added to the InitFunctions section? 
} 
) 

शायद वर्गों इस समस्या का सही समाधान नहीं हैं, लेकिन मैं जानता हूँ कि वहाँ कुछ हासिल करने के लिए एक तरह से हो गया है कि इस तरह। कोई विचार?

उत्तर

0

एक देर से प्रवेश के बारे में थोड़ी - लेकिन उम्मीद है कि अभी भी किसी को वहाँ के लिए उपयोगी:

अगर वहाँ एक देशी विधि इसे प्राप्त करने के लिए है, लेकिन मैं अब कुछ समय के लिए इस का उपयोग किया गया है और यह है मैं नहीं जानता वास्तव में सहायक:

public static IHtmlString Resource(this HtmlHelper HtmlHelper, Func<object, HelperResult> Template, string Type) 
{ 
    if(HtmlHelper.ViewContext.HttpContext.Items[Type] != null) ((List<Func<object, HelperResult>>)HtmlHelper.ViewContext.HttpContext.Items[Type]).Add(Template); 
    else HtmlHelper.ViewContext.HttpContext.Items[Type] = new List<Func<object, HelperResult>> { Template }; 

    return new HtmlString(String.Empty); 
} 

public static IHtmlString RenderResources(this HtmlHelper HtmlHelper, string Type) 
{ 
    if(HtmlHelper.ViewContext.HttpContext.Items[Type] == null) return new HtmlString(String.Empty); 

    var Resources = (List<Func<object, HelperResult>>)HtmlHelper.ViewContext.HttpContext.Items[Type]; 

    foreach(var Resource in Resources.Where(Resource => Resource != null)) 
    { 
     HtmlHelper.ViewContext.Writer.Write(Resource(null)); 
    } 

    return new HtmlString(String.Empty); 
} 

उपयोग है:

//This is how you save it 
@Html.Resource(@<style>.test{color: #4e4e4e}</style>, "css") 

//This is how you read it 
@Html.RenderResources("css") 
संबंधित मुद्दे