Subscribe: Custom Server Controls
http://forums.asp.net/rss.aspx?ForumID=19
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
code  context  control  data  gridview  length  new  nextjeneration webui  public  result  return  route  system  val length  val 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Custom Server Controls

All Forums



All Forums



Last Build Date: Mon, 18 Dec 2017 13:27:08 -0800

 



[HttpGet("{id}", Name = "GetTodo")]

2017-12-18T21:20:17.11-08:00

What does the highlighted line accomplish below?

using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using TodoApi.Models;
using System.Linq;

namespace TodoApi.Controllers
{
    [Route("api/todo")]
    public class TodoController : Controller
    {
        private readonly TodoContext _context;

        public TodoController(TodoContext context)
        {
            _context = context;

            if (_context.TodoItems.Count() == 0)
            {
                _context.TodoItems.Add(new TodoItem { Name = "Item1" });
                _context.SaveChanges();
            }
        }

        [HttpGet]
        public IEnumerable GetAll()
        {
            return _context.TodoItems.ToList();
        }

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       [HttpGet("{id}", Name = "GetTodo")]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        public IActionResult GetById(long id)
        {
            var item = _context.TodoItems.FirstOrDefault(t => t.Id == id);
            if (item == null)
            {
                return NotFound();
            }
            return new ObjectResult(item);
        }
   
    }
}




c# testing a webMethod using IQueryable works but does not after publishing

2017-12-18T21:07:33.4-08:00

I have developed web services using c# for a while now. And everything up till now worked fine, but today even though while debugging the code runs fine like it has been for few months now but when i publish the code and put it on a IIS it gives and error. the message is: The type or namespace name 'AKAB_Item_AKItem' could not be found the code which works while debugging but crashes when published. IQueryable akitemsswe = null; if (date_last_modified != null) { akitemsswe = from result in dc2.AKAB_Item_AKItems where result.Last_Date_Modified > DateTime.ParseExact(date_last_modified.ToString(), "dd.MM.yyyy HH:mm:ss", null) select result; } else { akitemsswe = from result in dc2.AKAB_Item_AKItems select result; } Am I missing something because i can not wrap my head around that the debugging works but the published project does not. And just to be sure - I have inspected the published files and the *.dbml contains  AKAB_Item_AKItem [...]



4.5 dynamic table I can't read it

2017-12-18T21:01:52.763-08:00

We just moved to 4.5.

We have a dynamically created asp table with drop down and text box controls on it.

There is a button that issues a post back and were trying to read the fields. Say someone changed a textbox text from 1 to 2.

On post back the field is Nothing. The 3.5 code use to read the table by Request.Item("statusb"). Now nothing comes.

If I read the controls with FindControl I get the values that was there before.

Any help would be appreciated.

Jon T




changes are not allowed if the project wasn't built when debugging started

2016-12-15T16:41:24.763-08:00

I have googled this and found lots of suggestions on what to do, but none of them work.

This was working just fine last week.  The only thing I've installed in the last week was SSMS 2016.

If anyone who has ideas on how to get passed this, I would appreciate it!




How to call an API to search a database from an ASP.Net MVC application

2017-12-14T19:40:03.97-08:00

I have an ASP.Net Core MVC website. I also have an ASP.Net Web API. I created a simple search function within the API to search an Oracle database with a search term input by a user into a textbox. What I want is to do the search from the MVC application. So I need to call the API and send it the search term, then return any results for display back to the MVC app. I believe I need to use GET to bring back data. Is there an example I could use? I am using Visual Studio 2017 and C#. Any help would be appreciated.




Deploying WebAPI

2017-12-18T20:38:20.763-08:00

Is there a good tutorial someone can recommend for (non Azure) deployment of WebAPI?




Exporting names to CSV, take two columns instead of one

2017-12-18T16:13:47.807-08:00

How do I get my name column to be one, stead of splitting as two? The output looks like this:

ID,saMAccountName,DisplayName
0,jdoe,Doe,John

I would like to surround the column separators with quotation marks like

"0","jdoe","Doe, John"

Here's the code:

            Response.ClearContent();
            Response.Clear();
            Response.ContentType = "text/plain";
            Response.AddHeader("Content-Disposition", "attachment; filename=DownloadedData.csv;");

            StringBuilder sb = new StringBuilder();

            string[] columnNames = dt.Columns.Cast().
                                              Select(column => column.ColumnName).
                                              ToArray();
            sb.AppendLine(string.Join(",", columnNames));

            foreach (DataRow row in dt.Rows)
            {
                string[] fields = row.ItemArray.Select(field => field.ToString()).
                                                ToArray();
                sb.AppendLine(string.Join(",", fields));
            }
            // the most easy way as you have type it
            Response.Write(sb.ToString());
            Response.Flush();
            Response.End();



IISADMPWD change password with e-mail

2017-12-15T08:29:06.667-08:00

We use IISADMPWD webapplication to allow users to change their AD account password. Some of our AD accounts dont have the same UPN as mail, but we are changing that for the new users. So the new users now have the same on both UPN and mail. Can I somehow add or modify IISADMPWD so it accept users e-mailaddress when changing password? Today it only works with UPN, is it possible to replace the attributes in the code to support mail instead? or perhaps add a feature to "search for users with this mail"? or search for user by mail and then get the users UPN to continue changing password? I believe the development of this feature should be made in the achg.asp file https://github.com/sysboss/IISADMPWD/blob/master/iisadmpwd/achg.asp I found this vbscript https://stackoverflow.com/questions/23843380/vbscript-get-username-from-mail But dont know how to implement it in a .asp file. Tried just to paste the script into <%  %> but got Internal error 500. Can anyone help me with this? Or is there another method that's better for me? I dont know how to code ASP C# ASP.NET. But Im comfy with powershell, lokal VBScript and PHP. Sincerely Fredrik [...]



data connect to a web form control

2017-12-18T17:09:48.33-08:00

Of the code listed above, can you tell me how the following statement knows how to connect the values listed below in the statement:  DataKeyNames="schoolyear, schoolnum, stulink, milestone_code, semester" to the gridvbiew control? Are these connected fields based upon following logic:     ', '<%# Eval("schoolnum") %>', '<%# Eval("milestone_code") %>', '<%# Eval("stulink") %>', '<%# Eval("HOMELNGCOR") %>', '<%# Eval("semester") %>');" style="color:Blue"><%#Eval("STUDENTNAME")%> If so, how does the javascript know how to connect the data to this gridview control? Here is the code to GetStudentLetterTemplate  function GetStudentLetterTemplate(schoolyear, schoolnum, milestone, studentlink, language, semester) {             if (language == '') {                 language = 'EN'             }             else if (language == 'SPA') {                 language = 'ES'             }             _schoolyear = schoolyear;             _schoolnum = schoolnum;             _milestone = milestone;             _studentlink = studentlink;             _language = language;             _semester = semester;             $('#<%= txtStuLink.ClientID%>').val(studentlink);             $('#<%= txtLanguage.ClientID%>').val(language);             var strData = "schoolyear: " + JSON.stringify(schoolyear) + ", "                 + "schoolnum: " + JSON.stringify(schoolnum) + ", "                 + "milestone: " + JSON.stringify(milestone) + ", "                 + "studentlink: " + JSON.stringify(studentlink) + ", "                 + "language: " + JSON.stringify(language) + ", "                 + "semester: " + JSON.stringify(semester) + "";             //alert('student data: ' + strData);             //make call to db and send ingredient information              $.ajax({                     type: "POST",               [...]



Int Parameter

2017-12-18T10:30:57.177-08:00

Hi

   I am displaying values in Month Parameter as 1,2,3,4,5,6,7,8,9,10,11,12.

In a report i want to display its Label Value.

Thanks




datakeys for gridview control

2017-12-18T19:31:39.8-08:00

In a vb.net 2010 web form application, I see that there is a gridview control that use datakeys. When I do a search on the web, it looks like datakeys are only used up until visual studio 2010. Is this correct? If so, what control/property/ and/or  logic is used to replace the data keys control on a gridview control?

If this is not true, up until what version of visual studio can I use for a gridview control?




Error: AmbiguousActionException: Multiple actions matched.

2017-12-18T18:31:52.487-08:00

I'm new to Core and I'm getting this error, what is the cause how do I fix it?

An unhandled exception occurred while processing the request.

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

NextJeneration.WebUI.Controllers.HomeController.Index (NextJeneration.WebUI)
NextJeneration.WebUI.Controllers.HomeController.Index (NextJeneration.WebUI)

Microsoft.AspNetCore.Mvc.Internal.ActionSelector.SelectBestCandidate(RouteContext context, IReadOnlyList candidates)

  • AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied: NextJeneration.WebUI.Controllers.HomeController.Index (NextJeneration.WebUI) NextJeneration.WebUI.Controllers.HomeController.Index (NextJeneration.WebUI)

Here is my Controller:

public class HomeController : AmtesControllerBaseController
    {
        public HomeController(IUserRepository repository, NextJeneration.Domain.Concrete.NextJenerationDbContext context) : base(repository, context)
        {
        }

        [AllowAnonymous]
        [Route("")]      // Combines to define the route template "Home"
        [Route("Index")] // Combines to define the route template "Home/Index"
        [Route("/")]     // Does not combine, defines the route template ""
        public async Task Index()
        {
            bool loggedIn = GetLoggedInStatus();
            if (loggedIn == false)
            {
                var myCAC = getCAC();
                await buildCACuser(myCAC);
            }
            return View();
        }

        [AllowAnonymous]
        [Route("LandingPage")] // Combines to define the route template "Home/LandingPage"
        [HttpGet("[controller]/[action]")]
        public IActionResult LandingPage()
        {
            UserEditViewModel userEditViewModel = new UserEditViewModel();
            var CAC = GetCacInfo();
            var user = userRepository.GetUserByCAC(CAC);
            userEditViewModel.UserStatusId = user.UserStatusId;
            userEditViewModel.Registered = user.Registered;

            if (!user.ThemeId.HasValue)
            {
                userEditViewModel.Theme = "~/lib/bootstrap/dist/css/bootstrap.css";
            }
            else
            {
                userEditViewModel.Theme = userRepository.GetThemeById(user.ThemeId.GetValueOrDefault());
            }

            ViewBag.CSS = userEditViewModel.Theme;

            return View("LandingPage", userEditViewModel);
        }

        //[AllowAnonymous]
        [Route("Error")] // Combines to define the route template "Home/Error"
        public IActionResult Error()
        {
            return View();
        }
    }



validation stopped working

2017-12-16T15:33:21.197-08:00

I am in desperate need of help. I used the following script to validate checkboxes and textboxes. The checkbox was outside gridview and the textboxes were inside gridview. User must either complete textboxes OR put a checkmark to the checkbox in other to submit the form. Management has decided that the checkbox must be inside gridview as well. As a result, I modified the script as shown below and now, the script doesn't valid anymore. It doesn't matter whether the checkbox is not checked and the textboxes are empty, it still submits. How do I change to class so it would be able to validate? This is what I am currently using.

*Check this box if N/A
getstoredproccommand(“procedurename”,new object[1]) throws 'System.AccessViolationException' in Microsoft.Practices.EnterpriseLibrary.Data.dll

2017-12-18T18:09:23.383-08:00

public static IEnumerable GetAll() { Database db = DatabaseFactory.CreateDatabase(); DbCommand objComm = db.GetStoredProcCommand("package name.procedurename", new object[1]); var result = new List(); using (IDataReader rdr = db.ExecuteReader(objComm)) { while (rdr.Read()) { result.Add(Construct(rdr)); } } return result; } and my store procedure is like this PROCEDURE PRC_PROCEDURE (resultset_out OUT TYPES.cursorType) AS BEGIN OPEN resultset_out FOR SELECT * FROM PORTALLISTS; END PRC_PORTALLISTS_GETALL; i am having error in this line DbCommand objComm = db.GetStoredProcCommand("package name.procedurename", new object[1]); if i do this DbCommand objComm = db.GetStoredProcCommand("package name.procedurename"); error is gone but then i am facing same error[Exception thrown: 'System.AccessViolationException' in Microsoft.Practices.EnterpriseLibrary.Data.dll] in this line using (IDataReader rdr = db.ExecuteReader(objComm)) . i am using dot.net framework 4 and Microsoft.Practices.EnterpriseLibrary.Data.dll version is 5.0.0.0. can you guys pls help me? and in portallistservices.cs file i have this public static IEnumerable GetAll() { return GetAll(true); } private static IEnumerable GetAll(bool forceDataReload) { const string cacheKey = "PortalListService_GetAll"; IEnumerable result = null; if (!forceDataReload) result = GetFromCache(cacheKey); if (result == null) { result = PortalListRepository.GetAll(); AddToCache(cacheKey, result); } return result; } [...]



How to load partialview into bootstrap modal dynamically

2017-12-18T15:05:59.92-08:00

suppose i have a button and when user will call then i will call a server action which will return partial view to client side means html with data. i need to show and put that data into  bootstrap modal dynamically. how it will be possible.

i will not leave bootstrap modal in advance in page rather bootstrap modal will be constructed at run time dynamically.

please give me code sample or article links.




Receiving live data on server

2017-12-17T11:22:32.01-08:00

Live weather data needs to be sent to my server 2012, so far i have created a .Net web page which can read query string and save it to some file on server. Its been hosted on IIS 8.0. Eaxmple(192.0.2.122/getdata.aspx?str=xyz)

I was wondering if this is a right way of receiving data on server? the other idea i had in mind was soap web services but not sure if it can add any benefits to what i have already done.

protected void Page_Load(object sender, System.EventArgs e)
{
  if (Request.QueryString.Count > 0)
  {
    string query = Request.QueryString("str");
    using (StreamWriter _testData = new StreamWriter(Server.MapPath("~/data.txt"), true))
    {
        _testData.WriteLine(query);
    }
  }
}



Disable ChangeTracking with EF 6.0

2017-12-18T10:56:22.6-08:00

I am wondering how can I really disable ChangeTracking per entity using Entity Framework 6.0 by calling AsNoTracking() method.

Here's my DataContext

using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.Validation;
//using System.Data.Objects;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace OrgData
{
	public class DataContext : DbContext, IDbContext
	{
		#region Constructors
			
		static DataContext()
		{
			// Set the db initialize to null so EF doesn't try to create our database for us
			Database.SetInitializer(null);
		}

		public DataContext(): base ("Name=Conn")
		{
			this.Configuration.AutoDetectChangesEnabled = false;
		}

		#endregion
			
		#region Data Sets
			
		public DbSet Projects
		{
			get;
			set;
		}

https://stackoverflow.com/questions/21918492/asnotracking-method-is-missing-from-context-in-entity-framework 

Could not install any of those packages!

Any help would be appreciated.




How to detect request is coming from mobile or tab

2017-12-18T15:03:27.543-08:00

with the help of javascript or jquery can we detect that request is coming from mobile or tab instead of desktop pc or laptop pc?

if possible please share the code. thanks




repeater group by

2017-12-18T15:24:27.1-08:00

I have records in my sql server db :

ID | StudyName|  StudyText    | StudyLink                         

1      study1         about ENR    http://www.en1.com      

2      study1         about ENRA    http://www.en1a.com   

3      study2         about ENR    http://www.en1.com   

I want to group the data so that the repeater will show me :

study1

about ENR    http://www.en1.com

about ENRA    http://www.en1a.com  

study2

study2         about ENR    http://www.en1.com  

any hint ?




Convert PHP Application to Asp.net

2017-12-15T18:30:31.707-08:00

Hi All,

There is a requirement where I need to convert PHP Application(what ever normal php pages or wordpress) to asp.net. Please let me know if there are any readymade for conversion. Its urgent for me.  Thanks in Advance