After migrating from mvc 3 to mvc 4 Razor v.2 wrong parse my js template.
Problem in the next {{if}} section
{{? (it.#Model.GetPropName(x => x.Children)).length < it.#Model.GetPropName(x => x.ChildTaskTotalCount)}}
{{?}}
Razor v2 parse second argument of condition(it.#Model.GetPropName(x => x.ChildTaskTotalCount) ) as a string. And dot.js throws error on client browser.
#Model.GetPropName()- function which returns name of model property.Other words it.#Model.GetPropName(x => x.ChildTaskTotalCount) equal to it.ChildTaskTotalCount, but (it.Children).length
This code block works correctly in asp.net mvc 3 with razor v.1.
How should i change syntax to correct work with razor v.2?
Related
There is pattern I used a lot of in ASP.NET MVC 5:
(string.Join("<br>", someList.Select(item => Html.DisplayFor(model => item)))
But in ASP.NET Core DisplayFor(..) now returns IHtmlContent, and IHtmlContent.ToString() now returns literaly "Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewBuffer", not a rendered content.
Which pattern should I use to fix code with minimal changes?
Which pattern is an idiomatic way to achieve this?
How do I retrieve the #odata.context value from a request to a aspnetcore 2.1 using odata v4 (microsoft aspnetcore.odata 7.0.1) inside the controller?
I needed to form my response as
{ "#odata.context":"https://localhost:5001/odata/$metadata#Products/$entity",
"value" :[{ "id":"b79a6aa2-ed65-400c-8f7d-42052412b0b4"}]
}
rather than ``{"#odata.context":"https://localhost:5001/odata/$metadata#Products/$entity","id":"b79a6aa2-ed65-400c-8f7d-42052412b0b4"}
Thank you!!
Alberto
It looks like your controller is returning a single value response, if you have it return an Enumerable then it'll be in the form you want
I have a problem with a yii rest api. I configured it to work following the tutorial on the yii framework page, but after that i realised that my api works BUT NOT some big PORTIONS of my PAGE since it is based on the GET URL format rather than PATH which is required by the rest api.
So in my config/main.php i have the following setting
'urlManager' => array (
'urlFormat' => 'path',
'rules' => array (
'student/<id:\d+>/<title:.*?>' => 'student/view',
'students/<tag:.*?>' => 'student/index',
array (
'apistudent/register',
'pattern' => 'api/<model:\w+>',
'verb' => 'POST'
),
'<controller:\w+>/<action:\w+>' => '<controller>/<action>'
)
),
I also have a controller named ApiStudentController with a method called actionRegister().
So as already stated the api works normally but my page does not since i set the urlFormat to be 'path'.
The question is... how can i use the rest api but without the PATH url format and rather the default get url format (index.php?r=apistudent/register)?
I too faced the same problem in yii 1.x. I just need my API controller alone in old GET format rather than in PATH format (as i changed my websites URLs in PATH format). Finally i got it worked with a small hack in script file
$app = Yii::createWebApplication($env->configWeb); //store the app
//Change the UrlFormat for urlManager to get if a get request is given instead of a path format one.
if (isset($_GET['r'])) {
Yii::app()->urlManager->setUrlFormat('get');
}
$app->run(); //run the app
I dont know whether this solves your problem. But this can give you an idea. Happy Coding!
I have created the internet application ASP.NET MVC Using RAZOR.
I have written in Index.cshtml as:
#Session["my"]="Hello".
and I have written in AboutUs.cshtml as:
#Session["my"]
Still now I can't get the value from AboutUs.cshtml .
Instead of it in Index.cshtml it shows:
="Hello"
Replace #Session["my"]="Hello"; with #{ Session["my"] = "Hello"; }.
Note the addition of curly brackets.
Microsoft has a good tutorial for getting your first ASP.NET Web API project going:
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
...but what's unclear to me -- how is the mapping between the API URIs and my C# controller methods defined?
for ex:
/api/products/{id}
resolves to
public IHttpActionResult GetProduct(int id)
{
[...]
}
...but im not sure how. automagic?
I ask because I want to create a new mapping for this URI:
/api/setReportNotificationsAsRead?uid={username}&items={itemIDs}
to this new method in my controller:
public IHttpActionResult SetReportNotificationsAsRead(string username, string itemIDs)
{
[...]
}
...but im not sure how. automagic?
The Automagic lies with HTTP Verbs in Web API. The route /api/products/{id} can map to anything that starts with GET (or just method name Get) if you make a GET request for the WebAPI.
If you make a POST request then it will map to any POST method (or else is you use route prefix).
This link can help you understand the magic. That can also help you understanding how you can configure SetReportNotificationsAsRead function to be called.
You're very close to having a working solution. You have your method parameter names mixed up:
public IHttpActionResult SetReportNotificationsAsRead(string uid, string items)
{
//Do your stuff!
}
The name of the HTTP GET parameter should match the name of the method parameter. This is part of the ASP.NET MVC naming convention.
One final note, if you are actually expecting a group of items (i.e. multiple item ids) you can actually save yourself some work and use a string[] parameter so long as your HTTP parameters are sent correctly. In this case you would want the URI to look like: /api/setReportNotificationsAsRead?items=123&items=456&items=789. Notice how the parameter name is repeated multiple times, but with different values.
For more information about the routing system I would suggest heading over to the ASP.NET MVC routing overview.