About ASP.NET Web Pages Global -


i new learner asp.net. saw “_appstart.cshtml”, “_pagestart.cshtml” , “_viewstart.cshtml” act global headers or footer.

(1)if want trigger right before page output, should put code in _viewstart.cshtml of others?

(2)let c html code before output, beside appending code c can replace code c? such making text uppercase or replace text?

(3)will asp.net cache process won't run each time?

benone

answer point 1

the _viewstart file can used define common view code want execute @ start of each view’s rendering. example, write code within our _viewstart.cshtml file programmatically set layout property each view sitelayout.cshtml file default

actually it's basepage in asp.net can keep common code.

or can write logic directly in view below.

@{   layout = "~/views/shared/_layout.cshtml";   if (some consition) {     layout = "~/views/shared/_adminlayout.cshtml";   } } 

alternatively

you can override action executing method, executes before executing action method. can set particular action method or complete controller

below code setting complete controller.

protected override void onactionexecuting(actionexecutingcontext ctx) {     base.onactionexecuting(ctx); } 

below code setting particular action method

[myattribute(someproperty = "")] public actionresult index() {      return view("index"); }  public class myattribute : actionfilterattribute {     public string someproperty { get; set; }     public override void onactionexecuting(actionexecutingcontext filtercontext)     {         base.onactionexecuting(filtercontext);     } } 

answer point 2

you can use

  var str = html.partial("_partial_view_name"); 

partial returns mvchtmlstring. can intercept output setting variable , make necessary change.

answer point 3

yes. below sample code

namespace mvcapplication1.controllers {     [handleerror]     public class homecontroller : controller     {         [outputcache(duration=10, varybyparam="none")]         public actionresult index()         {             return view();         }      } } 

the output of index() action cached 10 seconds


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -