Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this function to return a view
Function mostrar(cor As String, alinea As Char) As ActionResult
           ViewBag.cor = cor
           ViewBag.alinea = alinea
           Return View()
       End Function


this is the view
Razor
@Code
    ViewBag.Title = "mostrar"
    End Code

<h2>mostrar</h2>
<h4>@viewbag.cor</h4>
<h4>@ViewBag.alinea</h4>


the function is called from code but no view is returned. But i know the parameters enter function.

if i put this in the URL:
http://localhost:16844/prescavi/mostrar?cor=red&alinea=s

The view works perfectly...
Posted
Updated 10-Oct-15 5:22am
v2
Comments
Zoltán Zörgő 10-Oct-15 12:10pm    
"the function is called from code" how exactly (from view or from controller)?
Nosfa 10-Oct-15 18:54pm    
I don't know the best way to this.
I have an input form and I pass the values to the controller by json.
Then the controller executs several methods and gets to a few results in strings or collections.
Those results must pass to a view.
(if the inputs are right the view returns a green light and an ocasional OK and if there are errors either a yellow or a red light and a description of why there's an error)

Calling the code as a function isn't going to generate html. If that's what you want to do then google "asp.net get html from controller programmatically" and you'll find examples of how to get the rendered html.
 
Share this answer
 
Use "Reply", so I get notified about your message. I got here by accident, and I saw your comment.

To be short: you can't make an ajax call and expect a "regular" effect. You either use ajax to talk to the backend or do regular POSTs or GETs.

When designing ajax backend call you can decide what that will return. It can return html (a partial view in your case) you can directry render into the current DOM, or json (xml, plain text, whatever) that you can parse and format as necessary on client side.

The simplest approach is using AjaxForm[^].

This is about the partial view approach: https://cmatskas.com/update-an-mvc-partial-view-with-ajax/[^]

On the other hand you have jQuery and you can tailor your ajax behavior as you like.
See: http://www.mikesdotnetting.com/article/220/posting-data-with-jquery-ajax-in-asp-net-razor-web-pages[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900