|
Hi,
I need help for show datatable in Json
My project is MVC:
My AgendaModel
<pre> public List<AgendaModel> MostrarTodosCalendar()
{
List<AgendaModel> lista = new List<AgendaModel>();
AgendaModel item;
DAL objDAL = new DAL();
string sql = "SELECT id, title, start, end, AllDay, Color, TextColor FROM agenda";
DataTable dt = objDAL.RetDataTable(sql);
for (int i = 0; i < dt.Rows.Count; i++)
{
item = new AgendaModel
{
Id = dt.Rows[i]["Id"].ToString(),
Title = dt.Rows[i]["Title"].ToString(),
Start = dt.Rows[i]["Start"].ToString(),
End = dt.Rows[i]["End"].ToString(),
Color = dt.Rows[i]["Color"].ToString(),
TextColor = dt.Rows[i]["TextColor"].ToString()
};
lista.Add(item);
}
return lista;
}
My View: Index:
function CriarEventosCalendario() {
var events = [];
@{
foreach(var item in (List<AgendaModel>)ViewBag.ListaEventos)
{<text>events.push({
'id': @item.Id,
'title': '@item.Title',
'start': '@item.Start',
'end': '@item.End',
'allDay': false,
'color': '@item.Color',
'textColor': '@item.TextColor'
});</text>
}
}
I want to convert to JSON because fullcalendar is not showing the data as it currently is.
|
|
|
|
|
Change the events declaration in the view to
function CriarEventosCalendario() {
var events = @Html.Raw(Json.Encode(ViewBag.ListaEventos));
|
|
|
|
|
I have error in
Encode
You can help me ?
|
|
|
|
|
|
Erro CS1061 ‘IJsonHelper’ does not contain a definition for "Encode"..
|
|
|
|
|
You're using ASP.NET Core. Instead of:
var events = @Html.Raw(Json.Encode(ViewBag.ListaEventos)); use:
var events = @Json.Serialize(ViewBag.ListaEventos);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hello , guys I am working on hotel system can any body share source code with me please, its very important!
this's my email "showmore5@gmail.com"
thanks very much
|
|
|
|
|
No, nobody here is going to do your work for you.
And it's not "very important" to anyone other than you.
If you want to hire someone to write some code for you, there are sites where you can do that. This isn't one of them.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I worked on a booking system in the 90s, it took approx 18 months to build, not test just build. Mind you it is in SuperBase!
I can send you that code for a small recompense.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I did laugh out loud at that!
I think I can probably find mine from the 80's - developed for C/PM though so probably a bit more expensive than yours
|
|
|
|
|
HAHAHAHA
Member 14921707 wrote: its very important!
If it was, you'd be paying and not begging.There's free solutions available. What makes you think I take the time to build you a new one, without pay?
How much time (aka money) do you think one needs to put into building one?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'm sort of fuzzy on this here. So I have a HttpPost operation that ends with return Ok(result). I remember reading that I have to add a route to GetOrder in order for CreatedAtRoute to work. I sort of did something stupid and named that api GetAdminOrders so I can secure it with JWT, but added a Route decorator to it so CreatedAtRoute would work.
var result = CreatedAtRoute("GetOrder", new { order.Id }, order);
return Ok(result);
So this didn't work, it didn't return the order back to the client making the call. I just need the order number or Id of the order and not the whole order. Now I'm wondering if I should refactor all of these that I created. I'm really wondering if I got this all wrong here.
[HttpGet("GetAdminOrder/{orderId}"), Authorize(AuthenticationSchemes = AuthSchemes, Policy = AuthPolicies.Admin)]
[Route("{orderId}", Name = "GetOrder")]
public async Task<GetAdminOrder> GetAdminOrder(string orderId)
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I flipped the 2 around, and changed the route to include the route decorator at the top of the controller.
I guess this route decorator wiped out the first route decorator.
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]
public class StoreController : ControllerBase
[Route("{orderId}", Name = "api/[controller]/GetOrder")]<br />
[HttpGet("GetAdminOrder/{orderId}"), Authorize(AuthenticationSchemes = AuthSchemes, Policy = AuthPolicies.Admin)]
public async Task<GetAdminOrder> GetAdminOrder(string orderId)
On this, it worked before, but since the .Net Core upgrade, it has changed. Now it sends the order wrapped in Url and Value. So I changed my client to expect a value of "any", and coded the expected order number and token as result.Value.OrderNumber
var result = CreatedAtRoute("GetOrder", new { order.Id }, order);
return Ok(result);
It works, not sure if it's fixed.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
jkirkerx wrote:
CreatedAtRoute("GetOrder", new { order.Id }, order)
...
HttpGet("GetAdminOrder/{orderId}") IIRC, the parameters passed to CreatedAtRoute need to have the same names as the route parameters.
Your route has orderId , but you parameters has just Id .
Try changing the parameters to match.
You don't need to add both HttpGet and Route attributes.
You should also return the CreatedAtRoute result directly, rather than wrapping it in an Ok result.
return CreatedAtRoute("GetOrder", new { orderId = order.Id }, order);
[HttpGet("GetAdminOrder/{orderId}", Name = "GetOrder"), Authorize(AuthenticationSchemes = AuthSchemes, Policy = AuthPolicies.Admin)]
public async Task<Order> GetAdminOrder(string orderId)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I didn't think of it like that.
At the beginning before I wrote the JWT auth policies, I tried to make the app really code compact. It was just "GetOrder", then I renamed it to "GetAdminOrder" to reflect JWT Auth. I really need to streamline this naming.
return CreatedAtRoute directly? No need to return Ok. I wonder if using Ok wraps the JSON result in that extra envelope. I'll find out here, takes 10 mins to test it.
I made the code changes, and will give it a try, I'm sure it will work fine. I really don't want the extra route decorator anyways, it was just part of an example of using CreatedAtRoute I picked up over a year ago. I must admit that using CreatedAtRoute is pretty handy.
var result = CreatedAtRoute("GetAdminOrder", new { orderId = order.Id }, order);
return Ok(result);
[HttpGet("GetAdminOrder/{orderId}", Name = "GetOrder"), Authorize(AuthenticationSchemes = AuthSchemes, Policy = AuthPolicies.Admin)]
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
That worked out really well!
Thanks Richard
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
kindly help me to solve this issue.....i have Created a Login website - Validation Controls Registration Page but my submit button doesn't show message code i wrote which was:-
Response.Write("YOU HAVE SUCCESSFULLY REGISTERED...!!!!");
|
|
|
|
|
Please edit your question and show the code that has the problem. Without it it is impossible to guess what may be wrong.
|
|
|
|
|
button code was one line code and here it is,
Response.Write("you have successfully registered!!!");
once i fill out my web form registration form and i click on submit button nothing is displayed from what i wrote on button code(submit)
|
|
|
|
|
Please read my suggestion again.
|
|
|
|
|
but i didn't understand ..kindly break it for me
|
|
|
|
|
In addition to what Richard said, asp.net doesn't work like that, response.write is useless in 99% of occasions. If you view the source of your page you'll probably see your message right at the very bottom where it is no use at all. If you want to show a message in a particular place use an empty asp:Label or asp:Literal and when you want the message to be there set the Text of the label\literal to your message, you can also use the Visible property to show\hide it.
|
|
|
|
|
Kindly where can i find asp:label? or literal and how am i going to use it? kindly direct me
|
|
|
|
|
|
Just the same way you used to add the button control, same way you will find the Label control and add it.
Or just copy this
<asp:Label ID="Label1" Text="Label1" runat="server"/>
Then from codebehind, enter this code on your submit button event.
Label1.Text = "You have successfully registered";
|
|
|
|