Overriding ActionResult without caching data












3















I've create a SitemapResult class that derives from ActionResult. It allows the caller to add any number of URL resources, and it then outputs sitemap data in XML format.



public class SitemapResult : ActionResult
{
private List<SitemapUrl> SitemapItems;

public SitemapResult()
{
SitemapItems = new List<SitemapUrl>();
}

public void AddUrl(string url, DateTime? lastModified = null, SitemapFrequency? frequency = null, double? priority = null)
{
AddUrl(new SitemapUrl(url, lastModified, frequency, priority));
}

public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/xml; charset=utf-8";

using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
{

// TODO: Write sitemap data to output

}
}
}


The problem is that the class stores all the URLs until ExecuteResult() is called. It seems like it would be more efficient if I could write each URL to the response as they are added rather than hold them all in memory and then write every thing at once.



Does anyone know of any good examples of overriding ActionResult to write data to the response as it becomes available? In this case, I would think ExecuteResult() won't need to write anything at all.










share|improve this question

























  • Well unless you are passing the response when creating the result then it only has access to it via teh context in the ExecuteResult method

    – Nkosi
    Nov 27 '18 at 19:50











  • @Nkosi: I've added the basic layout but I'm not sure exactly what you wanted to see, since you didn't say.

    – Jonathan Wood
    Nov 27 '18 at 19:54






  • 1





    You could store a Func<IEnumerable<SiteMapUrl>> and call that in ExecuteResult. The calls to AddUrl would then be replaced with yield returns. (A simple IEnumerable could also do, actually, the Func isn't necessary if there's not a lot of setup to get the enumeration going.)

    – Jeroen Mostert
    Nov 27 '18 at 19:59








  • 1





    The SitemapItems could be passed as a constructor arg and used to populate result as well.

    – Nkosi
    Nov 27 '18 at 20:01






  • 1





    I am wondering if this might be premature optimization

    – Nkosi
    Nov 27 '18 at 20:01
















3















I've create a SitemapResult class that derives from ActionResult. It allows the caller to add any number of URL resources, and it then outputs sitemap data in XML format.



public class SitemapResult : ActionResult
{
private List<SitemapUrl> SitemapItems;

public SitemapResult()
{
SitemapItems = new List<SitemapUrl>();
}

public void AddUrl(string url, DateTime? lastModified = null, SitemapFrequency? frequency = null, double? priority = null)
{
AddUrl(new SitemapUrl(url, lastModified, frequency, priority));
}

public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/xml; charset=utf-8";

using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
{

// TODO: Write sitemap data to output

}
}
}


The problem is that the class stores all the URLs until ExecuteResult() is called. It seems like it would be more efficient if I could write each URL to the response as they are added rather than hold them all in memory and then write every thing at once.



Does anyone know of any good examples of overriding ActionResult to write data to the response as it becomes available? In this case, I would think ExecuteResult() won't need to write anything at all.










share|improve this question

























  • Well unless you are passing the response when creating the result then it only has access to it via teh context in the ExecuteResult method

    – Nkosi
    Nov 27 '18 at 19:50











  • @Nkosi: I've added the basic layout but I'm not sure exactly what you wanted to see, since you didn't say.

    – Jonathan Wood
    Nov 27 '18 at 19:54






  • 1





    You could store a Func<IEnumerable<SiteMapUrl>> and call that in ExecuteResult. The calls to AddUrl would then be replaced with yield returns. (A simple IEnumerable could also do, actually, the Func isn't necessary if there's not a lot of setup to get the enumeration going.)

    – Jeroen Mostert
    Nov 27 '18 at 19:59








  • 1





    The SitemapItems could be passed as a constructor arg and used to populate result as well.

    – Nkosi
    Nov 27 '18 at 20:01






  • 1





    I am wondering if this might be premature optimization

    – Nkosi
    Nov 27 '18 at 20:01














3












3








3


1






I've create a SitemapResult class that derives from ActionResult. It allows the caller to add any number of URL resources, and it then outputs sitemap data in XML format.



public class SitemapResult : ActionResult
{
private List<SitemapUrl> SitemapItems;

public SitemapResult()
{
SitemapItems = new List<SitemapUrl>();
}

public void AddUrl(string url, DateTime? lastModified = null, SitemapFrequency? frequency = null, double? priority = null)
{
AddUrl(new SitemapUrl(url, lastModified, frequency, priority));
}

public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/xml; charset=utf-8";

using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
{

// TODO: Write sitemap data to output

}
}
}


The problem is that the class stores all the URLs until ExecuteResult() is called. It seems like it would be more efficient if I could write each URL to the response as they are added rather than hold them all in memory and then write every thing at once.



Does anyone know of any good examples of overriding ActionResult to write data to the response as it becomes available? In this case, I would think ExecuteResult() won't need to write anything at all.










share|improve this question
















I've create a SitemapResult class that derives from ActionResult. It allows the caller to add any number of URL resources, and it then outputs sitemap data in XML format.



public class SitemapResult : ActionResult
{
private List<SitemapUrl> SitemapItems;

public SitemapResult()
{
SitemapItems = new List<SitemapUrl>();
}

public void AddUrl(string url, DateTime? lastModified = null, SitemapFrequency? frequency = null, double? priority = null)
{
AddUrl(new SitemapUrl(url, lastModified, frequency, priority));
}

public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/xml; charset=utf-8";

using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
{

// TODO: Write sitemap data to output

}
}
}


The problem is that the class stores all the URLs until ExecuteResult() is called. It seems like it would be more efficient if I could write each URL to the response as they are added rather than hold them all in memory and then write every thing at once.



Does anyone know of any good examples of overriding ActionResult to write data to the response as it becomes available? In this case, I would think ExecuteResult() won't need to write anything at all.







c# asp.net asp.net-mvc actionresult






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 19:54







Jonathan Wood

















asked Nov 27 '18 at 19:45









Jonathan WoodJonathan Wood

42.9k56190311




42.9k56190311













  • Well unless you are passing the response when creating the result then it only has access to it via teh context in the ExecuteResult method

    – Nkosi
    Nov 27 '18 at 19:50











  • @Nkosi: I've added the basic layout but I'm not sure exactly what you wanted to see, since you didn't say.

    – Jonathan Wood
    Nov 27 '18 at 19:54






  • 1





    You could store a Func<IEnumerable<SiteMapUrl>> and call that in ExecuteResult. The calls to AddUrl would then be replaced with yield returns. (A simple IEnumerable could also do, actually, the Func isn't necessary if there's not a lot of setup to get the enumeration going.)

    – Jeroen Mostert
    Nov 27 '18 at 19:59








  • 1





    The SitemapItems could be passed as a constructor arg and used to populate result as well.

    – Nkosi
    Nov 27 '18 at 20:01






  • 1





    I am wondering if this might be premature optimization

    – Nkosi
    Nov 27 '18 at 20:01



















  • Well unless you are passing the response when creating the result then it only has access to it via teh context in the ExecuteResult method

    – Nkosi
    Nov 27 '18 at 19:50











  • @Nkosi: I've added the basic layout but I'm not sure exactly what you wanted to see, since you didn't say.

    – Jonathan Wood
    Nov 27 '18 at 19:54






  • 1





    You could store a Func<IEnumerable<SiteMapUrl>> and call that in ExecuteResult. The calls to AddUrl would then be replaced with yield returns. (A simple IEnumerable could also do, actually, the Func isn't necessary if there's not a lot of setup to get the enumeration going.)

    – Jeroen Mostert
    Nov 27 '18 at 19:59








  • 1





    The SitemapItems could be passed as a constructor arg and used to populate result as well.

    – Nkosi
    Nov 27 '18 at 20:01






  • 1





    I am wondering if this might be premature optimization

    – Nkosi
    Nov 27 '18 at 20:01

















Well unless you are passing the response when creating the result then it only has access to it via teh context in the ExecuteResult method

– Nkosi
Nov 27 '18 at 19:50





Well unless you are passing the response when creating the result then it only has access to it via teh context in the ExecuteResult method

– Nkosi
Nov 27 '18 at 19:50













@Nkosi: I've added the basic layout but I'm not sure exactly what you wanted to see, since you didn't say.

– Jonathan Wood
Nov 27 '18 at 19:54





@Nkosi: I've added the basic layout but I'm not sure exactly what you wanted to see, since you didn't say.

– Jonathan Wood
Nov 27 '18 at 19:54




1




1





You could store a Func<IEnumerable<SiteMapUrl>> and call that in ExecuteResult. The calls to AddUrl would then be replaced with yield returns. (A simple IEnumerable could also do, actually, the Func isn't necessary if there's not a lot of setup to get the enumeration going.)

– Jeroen Mostert
Nov 27 '18 at 19:59







You could store a Func<IEnumerable<SiteMapUrl>> and call that in ExecuteResult. The calls to AddUrl would then be replaced with yield returns. (A simple IEnumerable could also do, actually, the Func isn't necessary if there's not a lot of setup to get the enumeration going.)

– Jeroen Mostert
Nov 27 '18 at 19:59






1




1





The SitemapItems could be passed as a constructor arg and used to populate result as well.

– Nkosi
Nov 27 '18 at 20:01





The SitemapItems could be passed as a constructor arg and used to populate result as well.

– Nkosi
Nov 27 '18 at 20:01




1




1





I am wondering if this might be premature optimization

– Nkosi
Nov 27 '18 at 20:01





I am wondering if this might be premature optimization

– Nkosi
Nov 27 '18 at 20:01












1 Answer
1






active

oldest

votes


















1














What you are trying to achieve, is building your model inside the view (custom view)... that's not a good practice... in MVC, controllers are responsible for building the model and passing it to the view... views are responsible for displaying the model and should have as little logic as possible.






It seems like it would be more efficient if I could write each URL to
the response as they are added rather than hold them all in memory and
then write every thing at once.




Why? You need to keep SitemapItems somewhere in the memory, so even if you write them to response, they are still kept in memory until you return the response... and I think it would be more efficient to serialize the whole list to XML at one go, as opposed to serializing each SitemapUrl individually.





There is a very elegant solution to your question on this pluralsight course:



public class SitemapResult : ActionResult
{
private object _data;

public SitemapResult(object data)
{
_data = data;
}

public override void ExecuteResult(ControllerContext context)
{
// you can use reflection to determine object type
XmlSerializer serializer = new XmlSerializer(_data.GetType());
var response = context.HttpContext.Response;
response.ContentType = "text/xml";
serializer.Serialize(response.Output, _data);
}
}


And you build your model in the controller, and pass it to the view:



return new SitemapResult(SitemapItems);




If you want to directly write to the Response you can do it in the controller:



public MyController : controller
{
public void GetSiteMapUrls()
{
XmlSerializer serializer = new XmlSerializer(SitemapItems.GetType());
Response.ContentType = "text/xml";
serializer.Serialize(Response.Output, SitemapItems);
}
}





share|improve this answer


























  • I'm getting the data from various sources, including the database. It is not necessary to store the entire list in memory except to cache the results before sending them to the response. It clearly seems more efficient not to cache that data. Moreover, it seems like it would be much faster if there was a way to send the data as I'm collecting it rather than caching it first. The code you posted is very similar to the code I posted. Mine just helps collect the data. I can experiment with using XmlSerializer of XmlWriter, but as I've described, this doesn't seem the most efficient approach.

    – Jonathan Wood
    Nov 28 '18 at 9:59











  • I am not sure if I understood... you have a list of urls, right? You don't want to store the entire list in memory - but isn't the entire list going to be added to response in serialized xml?

    – Hooman Bahreini
    Nov 28 '18 at 10:10











  • I construct a list of URLs. But that extra step seems unnecessary to me. I'd rather just send each URL to the response as I find it rather than storing it in a separate collection in memory.

    – Jonathan Wood
    Nov 28 '18 at 10:13











  • If you don't want the list of URLs, you can directly write it to the response, in controller (see updated answer). If I have understood you correctly, what you want is to build your Serialized XML list in the SiteMapResult... that is not how MVC is designed. Model is supposed to be built in controller and passed to the view.

    – Hooman Bahreini
    Nov 28 '18 at 10:30











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53507035%2foverriding-actionresult-without-caching-data%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














What you are trying to achieve, is building your model inside the view (custom view)... that's not a good practice... in MVC, controllers are responsible for building the model and passing it to the view... views are responsible for displaying the model and should have as little logic as possible.






It seems like it would be more efficient if I could write each URL to
the response as they are added rather than hold them all in memory and
then write every thing at once.




Why? You need to keep SitemapItems somewhere in the memory, so even if you write them to response, they are still kept in memory until you return the response... and I think it would be more efficient to serialize the whole list to XML at one go, as opposed to serializing each SitemapUrl individually.





There is a very elegant solution to your question on this pluralsight course:



public class SitemapResult : ActionResult
{
private object _data;

public SitemapResult(object data)
{
_data = data;
}

public override void ExecuteResult(ControllerContext context)
{
// you can use reflection to determine object type
XmlSerializer serializer = new XmlSerializer(_data.GetType());
var response = context.HttpContext.Response;
response.ContentType = "text/xml";
serializer.Serialize(response.Output, _data);
}
}


And you build your model in the controller, and pass it to the view:



return new SitemapResult(SitemapItems);




If you want to directly write to the Response you can do it in the controller:



public MyController : controller
{
public void GetSiteMapUrls()
{
XmlSerializer serializer = new XmlSerializer(SitemapItems.GetType());
Response.ContentType = "text/xml";
serializer.Serialize(Response.Output, SitemapItems);
}
}





share|improve this answer


























  • I'm getting the data from various sources, including the database. It is not necessary to store the entire list in memory except to cache the results before sending them to the response. It clearly seems more efficient not to cache that data. Moreover, it seems like it would be much faster if there was a way to send the data as I'm collecting it rather than caching it first. The code you posted is very similar to the code I posted. Mine just helps collect the data. I can experiment with using XmlSerializer of XmlWriter, but as I've described, this doesn't seem the most efficient approach.

    – Jonathan Wood
    Nov 28 '18 at 9:59











  • I am not sure if I understood... you have a list of urls, right? You don't want to store the entire list in memory - but isn't the entire list going to be added to response in serialized xml?

    – Hooman Bahreini
    Nov 28 '18 at 10:10











  • I construct a list of URLs. But that extra step seems unnecessary to me. I'd rather just send each URL to the response as I find it rather than storing it in a separate collection in memory.

    – Jonathan Wood
    Nov 28 '18 at 10:13











  • If you don't want the list of URLs, you can directly write it to the response, in controller (see updated answer). If I have understood you correctly, what you want is to build your Serialized XML list in the SiteMapResult... that is not how MVC is designed. Model is supposed to be built in controller and passed to the view.

    – Hooman Bahreini
    Nov 28 '18 at 10:30
















1














What you are trying to achieve, is building your model inside the view (custom view)... that's not a good practice... in MVC, controllers are responsible for building the model and passing it to the view... views are responsible for displaying the model and should have as little logic as possible.






It seems like it would be more efficient if I could write each URL to
the response as they are added rather than hold them all in memory and
then write every thing at once.




Why? You need to keep SitemapItems somewhere in the memory, so even if you write them to response, they are still kept in memory until you return the response... and I think it would be more efficient to serialize the whole list to XML at one go, as opposed to serializing each SitemapUrl individually.





There is a very elegant solution to your question on this pluralsight course:



public class SitemapResult : ActionResult
{
private object _data;

public SitemapResult(object data)
{
_data = data;
}

public override void ExecuteResult(ControllerContext context)
{
// you can use reflection to determine object type
XmlSerializer serializer = new XmlSerializer(_data.GetType());
var response = context.HttpContext.Response;
response.ContentType = "text/xml";
serializer.Serialize(response.Output, _data);
}
}


And you build your model in the controller, and pass it to the view:



return new SitemapResult(SitemapItems);




If you want to directly write to the Response you can do it in the controller:



public MyController : controller
{
public void GetSiteMapUrls()
{
XmlSerializer serializer = new XmlSerializer(SitemapItems.GetType());
Response.ContentType = "text/xml";
serializer.Serialize(Response.Output, SitemapItems);
}
}





share|improve this answer


























  • I'm getting the data from various sources, including the database. It is not necessary to store the entire list in memory except to cache the results before sending them to the response. It clearly seems more efficient not to cache that data. Moreover, it seems like it would be much faster if there was a way to send the data as I'm collecting it rather than caching it first. The code you posted is very similar to the code I posted. Mine just helps collect the data. I can experiment with using XmlSerializer of XmlWriter, but as I've described, this doesn't seem the most efficient approach.

    – Jonathan Wood
    Nov 28 '18 at 9:59











  • I am not sure if I understood... you have a list of urls, right? You don't want to store the entire list in memory - but isn't the entire list going to be added to response in serialized xml?

    – Hooman Bahreini
    Nov 28 '18 at 10:10











  • I construct a list of URLs. But that extra step seems unnecessary to me. I'd rather just send each URL to the response as I find it rather than storing it in a separate collection in memory.

    – Jonathan Wood
    Nov 28 '18 at 10:13











  • If you don't want the list of URLs, you can directly write it to the response, in controller (see updated answer). If I have understood you correctly, what you want is to build your Serialized XML list in the SiteMapResult... that is not how MVC is designed. Model is supposed to be built in controller and passed to the view.

    – Hooman Bahreini
    Nov 28 '18 at 10:30














1












1








1







What you are trying to achieve, is building your model inside the view (custom view)... that's not a good practice... in MVC, controllers are responsible for building the model and passing it to the view... views are responsible for displaying the model and should have as little logic as possible.






It seems like it would be more efficient if I could write each URL to
the response as they are added rather than hold them all in memory and
then write every thing at once.




Why? You need to keep SitemapItems somewhere in the memory, so even if you write them to response, they are still kept in memory until you return the response... and I think it would be more efficient to serialize the whole list to XML at one go, as opposed to serializing each SitemapUrl individually.





There is a very elegant solution to your question on this pluralsight course:



public class SitemapResult : ActionResult
{
private object _data;

public SitemapResult(object data)
{
_data = data;
}

public override void ExecuteResult(ControllerContext context)
{
// you can use reflection to determine object type
XmlSerializer serializer = new XmlSerializer(_data.GetType());
var response = context.HttpContext.Response;
response.ContentType = "text/xml";
serializer.Serialize(response.Output, _data);
}
}


And you build your model in the controller, and pass it to the view:



return new SitemapResult(SitemapItems);




If you want to directly write to the Response you can do it in the controller:



public MyController : controller
{
public void GetSiteMapUrls()
{
XmlSerializer serializer = new XmlSerializer(SitemapItems.GetType());
Response.ContentType = "text/xml";
serializer.Serialize(Response.Output, SitemapItems);
}
}





share|improve this answer















What you are trying to achieve, is building your model inside the view (custom view)... that's not a good practice... in MVC, controllers are responsible for building the model and passing it to the view... views are responsible for displaying the model and should have as little logic as possible.






It seems like it would be more efficient if I could write each URL to
the response as they are added rather than hold them all in memory and
then write every thing at once.




Why? You need to keep SitemapItems somewhere in the memory, so even if you write them to response, they are still kept in memory until you return the response... and I think it would be more efficient to serialize the whole list to XML at one go, as opposed to serializing each SitemapUrl individually.





There is a very elegant solution to your question on this pluralsight course:



public class SitemapResult : ActionResult
{
private object _data;

public SitemapResult(object data)
{
_data = data;
}

public override void ExecuteResult(ControllerContext context)
{
// you can use reflection to determine object type
XmlSerializer serializer = new XmlSerializer(_data.GetType());
var response = context.HttpContext.Response;
response.ContentType = "text/xml";
serializer.Serialize(response.Output, _data);
}
}


And you build your model in the controller, and pass it to the view:



return new SitemapResult(SitemapItems);




If you want to directly write to the Response you can do it in the controller:



public MyController : controller
{
public void GetSiteMapUrls()
{
XmlSerializer serializer = new XmlSerializer(SitemapItems.GetType());
Response.ContentType = "text/xml";
serializer.Serialize(Response.Output, SitemapItems);
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 28 '18 at 10:22

























answered Nov 28 '18 at 6:04









Hooman BahreiniHooman Bahreini

4,0433834




4,0433834













  • I'm getting the data from various sources, including the database. It is not necessary to store the entire list in memory except to cache the results before sending them to the response. It clearly seems more efficient not to cache that data. Moreover, it seems like it would be much faster if there was a way to send the data as I'm collecting it rather than caching it first. The code you posted is very similar to the code I posted. Mine just helps collect the data. I can experiment with using XmlSerializer of XmlWriter, but as I've described, this doesn't seem the most efficient approach.

    – Jonathan Wood
    Nov 28 '18 at 9:59











  • I am not sure if I understood... you have a list of urls, right? You don't want to store the entire list in memory - but isn't the entire list going to be added to response in serialized xml?

    – Hooman Bahreini
    Nov 28 '18 at 10:10











  • I construct a list of URLs. But that extra step seems unnecessary to me. I'd rather just send each URL to the response as I find it rather than storing it in a separate collection in memory.

    – Jonathan Wood
    Nov 28 '18 at 10:13











  • If you don't want the list of URLs, you can directly write it to the response, in controller (see updated answer). If I have understood you correctly, what you want is to build your Serialized XML list in the SiteMapResult... that is not how MVC is designed. Model is supposed to be built in controller and passed to the view.

    – Hooman Bahreini
    Nov 28 '18 at 10:30



















  • I'm getting the data from various sources, including the database. It is not necessary to store the entire list in memory except to cache the results before sending them to the response. It clearly seems more efficient not to cache that data. Moreover, it seems like it would be much faster if there was a way to send the data as I'm collecting it rather than caching it first. The code you posted is very similar to the code I posted. Mine just helps collect the data. I can experiment with using XmlSerializer of XmlWriter, but as I've described, this doesn't seem the most efficient approach.

    – Jonathan Wood
    Nov 28 '18 at 9:59











  • I am not sure if I understood... you have a list of urls, right? You don't want to store the entire list in memory - but isn't the entire list going to be added to response in serialized xml?

    – Hooman Bahreini
    Nov 28 '18 at 10:10











  • I construct a list of URLs. But that extra step seems unnecessary to me. I'd rather just send each URL to the response as I find it rather than storing it in a separate collection in memory.

    – Jonathan Wood
    Nov 28 '18 at 10:13











  • If you don't want the list of URLs, you can directly write it to the response, in controller (see updated answer). If I have understood you correctly, what you want is to build your Serialized XML list in the SiteMapResult... that is not how MVC is designed. Model is supposed to be built in controller and passed to the view.

    – Hooman Bahreini
    Nov 28 '18 at 10:30

















I'm getting the data from various sources, including the database. It is not necessary to store the entire list in memory except to cache the results before sending them to the response. It clearly seems more efficient not to cache that data. Moreover, it seems like it would be much faster if there was a way to send the data as I'm collecting it rather than caching it first. The code you posted is very similar to the code I posted. Mine just helps collect the data. I can experiment with using XmlSerializer of XmlWriter, but as I've described, this doesn't seem the most efficient approach.

– Jonathan Wood
Nov 28 '18 at 9:59





I'm getting the data from various sources, including the database. It is not necessary to store the entire list in memory except to cache the results before sending them to the response. It clearly seems more efficient not to cache that data. Moreover, it seems like it would be much faster if there was a way to send the data as I'm collecting it rather than caching it first. The code you posted is very similar to the code I posted. Mine just helps collect the data. I can experiment with using XmlSerializer of XmlWriter, but as I've described, this doesn't seem the most efficient approach.

– Jonathan Wood
Nov 28 '18 at 9:59













I am not sure if I understood... you have a list of urls, right? You don't want to store the entire list in memory - but isn't the entire list going to be added to response in serialized xml?

– Hooman Bahreini
Nov 28 '18 at 10:10





I am not sure if I understood... you have a list of urls, right? You don't want to store the entire list in memory - but isn't the entire list going to be added to response in serialized xml?

– Hooman Bahreini
Nov 28 '18 at 10:10













I construct a list of URLs. But that extra step seems unnecessary to me. I'd rather just send each URL to the response as I find it rather than storing it in a separate collection in memory.

– Jonathan Wood
Nov 28 '18 at 10:13





I construct a list of URLs. But that extra step seems unnecessary to me. I'd rather just send each URL to the response as I find it rather than storing it in a separate collection in memory.

– Jonathan Wood
Nov 28 '18 at 10:13













If you don't want the list of URLs, you can directly write it to the response, in controller (see updated answer). If I have understood you correctly, what you want is to build your Serialized XML list in the SiteMapResult... that is not how MVC is designed. Model is supposed to be built in controller and passed to the view.

– Hooman Bahreini
Nov 28 '18 at 10:30





If you don't want the list of URLs, you can directly write it to the response, in controller (see updated answer). If I have understood you correctly, what you want is to build your Serialized XML list in the SiteMapResult... that is not how MVC is designed. Model is supposed to be built in controller and passed to the view.

– Hooman Bahreini
Nov 28 '18 at 10:30




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53507035%2foverriding-actionresult-without-caching-data%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)