Questions tagged [viewresult]

31 questions
58
votes
6 answers

Must ASP.NET MVC Controller Methods Return ActionResult?

Being new to ASP.NET MVC, I've been wondering about the signature of Controller methods. In all the examples I've seen, they always seem to return ActionResult, even if they actually return a ViewResult instance or similar. Here's a commonly seen…
Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
25
votes
5 answers

How to set view model on ViewResult in request filter?

I make a MVC project and I want set Model into View from filter. But I do not kown ,How can I do this. the Model: public class TestModel { public int ID { get; set; } public string Name { get; set; } } Contorller: [CustomFilter(View =…
zt9788
  • 948
  • 4
  • 16
  • 31
6
votes
2 answers

RedirectToAction() vs. View() and the ternary operators?

when deciding on which ActionResult to return from a Controller Action I decided to use the ternary operators as opposed to the lengthier if-else. Here is my issue... this code works return ModelState.IsValid ? (ActionResult)…
Derrick W
  • 312
  • 3
  • 16
3
votes
0 answers

Get the result HTML from ViewResult

Possible Duplicates: Send asp.net mvc action result inside email Render a view as a string I would like to obtain the result HTML from one of my controller actions, and simply send the result as a HTML format email. However, I am having…
weilin8
  • 2,975
  • 3
  • 32
  • 36
3
votes
2 answers

Bestpractice DI with ASP.NET MVC and StructureMap - How to inject dependencies in an ActionResult

I edited my whole question, so do not wonder :) Well, I want to have an ActionResult that takes domain model data and some additional parameters, i.e page index and page size for paging a list. It decide itself if it returns a PartialViewResult or a…
Rookian
  • 19,841
  • 28
  • 110
  • 180
3
votes
4 answers

ASP.NET MVC - HybridViewResult (ViewResult /PartialViewResult)

Is it possible to build a hybrid ViewResult that returns in depedency of an AjaxRequest or HttpRequest a PartialViewResult or ViewResult? IsAjaxRequest --> return PartialViewResult !IsAjaxRequest --> return ViewResult As far as I know my…
Rookian
  • 19,841
  • 28
  • 110
  • 180
2
votes
1 answer

Unit test dependencies for an ASP.NET MVC 3 ViewResult subclass

I'm creating a really simple ViewResult subclass called JavaScriptViewResult that, when executing, calls the base implementation and then sets the Content-Type of the response to text/javascript. In trying to unit test this class, I'm running…
Jacob
  • 77,566
  • 24
  • 149
  • 228
2
votes
2 answers

MVC Redirect from a ViewResult where cannot change to ActionResult

I want to redirect from a ViewResult, so that I can display a specific product detail when the search result is 1 instead of the product list page. Other pages said to change the ViewResult to an ActionResult and to use the RedirectToAction. But…
user1408767
  • 677
  • 1
  • 8
  • 30
1
vote
1 answer

Couchdb: Read a View in Java

I am using couchdb for first time but I am facing a problem that I cannot find how to solve. I am creating an ad-hoc view with the following line ViewResults resultAdHoc = db.adhoc("function(doc) {emit(null, doc.name);}"); when I am running the…
x_maras
  • 2,177
  • 1
  • 25
  • 34
1
vote
2 answers

send view in email body mvc

I want to send a view in email body in mvc. please guide how to render view so that it can be sent as html email body. thanks,
Saboor Awan
  • 1,567
  • 4
  • 24
  • 37
1
vote
1 answer

MVC ViewResult.VIewName null even after setting it

I'm trying to write unit tests for a MVC application. im trying to test if my controller returns the correct view name. This is the controller action im testing: public IActionResult Index(string reportcode) { …
7uner
  • 13
  • 5
1
vote
0 answers

ViewResult class result not work when i submit a form method post for redirect to another view

when i sumit a form i want redirect to another page with viewresult class. this is my filter code : [ValidateSpamFilter(duration: 60, isAddress: false, keepRequestinCache: true)] // HttpPost Method For Submit Form . you can add comment by…
Amin Saadati 2
  • 95
  • 1
  • 10
1
vote
1 answer

ViewResult returns no data

I am using the pattern from NerdDinner. I call Index() in my test Method and I the ViewREsult I get back has no data. So the variable data ends up being null. However, I know that there is data there. Because I can go to the watch window and expand…
Jas
  • 13
  • 2
1
vote
3 answers

MVC4 PartialViewResult return a view and not a PartialView

I have an LogInOrRegister page in my application, that calls 2 child actions LogInOrRegister.cshtml @{ ViewBag.Title = "Log in"; } @Html.Action("Login", "Account", new { returlUrl = ViewBag.ReturnUrl}) @Html.Action("Register", new { returlUrl =…
Raphaël
  • 427
  • 5
  • 14
1
vote
1 answer

mvc3 unit testing best practice using serialize viewresult

I am looking into the best ways to unit test my MVC 3 controllers. I was thinking of taking the result of viewresult on executing the controller action with a bunch of different params, serializing it and saving to file as a base for future…
1
2 3