|
Sorry guys, it's a C# webAPI question.
I didn't see anything detailing specifically OData, so I thought it would fit in C#.
I don't think it's really a code specific question however, more of a question of Method. Here's my code below though. When an OData GET is called, this method fires, but even though I set a custom validator, the oData code is kicking out my request before it gets there, because "$inlineCount" is an unsupported method. My goal is to thow $inlineCount out of the REQUEST URL myself before it ever gets here. But I don't know when/where the request is getting blocked.
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All, PageSize = 5)]
public IHttpActionResult Get(ODataQueryOptions<Task> queryOptions)
{
try
{
queryOptions.Validator = new CustomValidator();
return Ok(_db.Tasks.AsQueryable());
}
catch (Exception e)
{
_logger.LogError(e.ToString());
return BadRequest(e.ToString());
}
}
|
|
|
|
|
Hello!
I'm new here hope you guys can give me a suggestions/answers to my questions.
I have an aspx page which has two dropdownlist the first dropdownlist populates school level and the second dropdownlist populate available section depending on the selected school level. I had enabled already the EnableViewState to TRUE from the page and to my master page. Below is my code.
On my Page Load event I populate the school level, I have this condition
If(!IsPostback)
{
PopulateSchoolLevel();
}
on my first dropdownlist selectedindexchanged event I have this code
Datatable dt = New DataTable;
dt=_queries("StoredProcedure",ddlLevel.SelectedValue.Tostring());
if(dt.rows!=0)
{
ddlSection.Datasource=dt;
ddlSection.ValueTextField="Section";
ddlSection.DataValueField="id";
ddlSection.DataBind();
}
now every time i select a value in my second dropdownlist it always return to the first index or first value. how can i retain the selected value on my second dropdownlist? I'm having burned a lot of time for this screnario.. please help me.
Thanks
|
|
|
|
|
Sorry, not enough code to fully answer but try this. I am running from memory now so I might be off a bit. I had a similar problem but found that I was forcing the second dropdown back to the first object. IIRC I also a selectedindex change event on the second dropdown and that was where my problem was.
If this doesn't help drop in more of the code.
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
every time you change the index you re-bind the data source.
a very simple solutions
session["current"] = ddlSection.selectedindex;
on page load
ddlSection.selectedIndex = convert.toint32(session["current"]);
|
|
|
|
|
Thanks for your replies.. i tried your suggestion by storing the selectedindex of my second dropdownlist into session. i put a breakpoint on Loading event to see if the selectedindex value was stored but unfortunately it was not stored,it always stored the first value of my second dropdownlist.. here are some of my codes below
private void _getSection()
{
ddlSection.Datasource=_queries("StoredProc",ddlLevel.SelectedIndexChanged);
ddlSection.DataTextField ="SectionName";
ddlSection.DataValueField="id";
ddlSection.DataBind();
}
private void _loadLevels()
{
//_queries is a class handles all queries to my sql database.
ddlLevel.Datasource=_queries("select * from levels");
ddlLevel.DataTextField ="LevelName";
ddlLevel.DataValueField ="id";
ddlLevel.DataBind();
}
on my pageload event i call the _loadLevels() function. I have this condition
if(!IsPostback)
{
_loadLevels();
}
if(Session["_sectionid"]!=null)
{
string _result = Session["_sectionid"].Tostring();
}
//---------------
protected void ddlLevel_SelectedIndexChanged(object sender, EventArgs e)
{
Session["_sectionid"]=ddlSection.Selectedindex;
_getSection(); //-- this will populate the section in my ddlSection which values are
ex. DataTextField DataValueField
St.Dominic 1
St.Agustine 2
}
Autopostback of my DDL's is set to True and EnableViewState from my masterpage is also set into True.
Every time i select the second or third item in my ddlSection it always give me the first index I can't understand???...Im sure that there is no event calling my _getSection function only in the ddlLevel. by the way Im using Masterpage but there is no code i have in my masterpage. Please let me know what's happening on this scenario?
modified 30-Jul-14 1:38am.
|
|
|
|
|
Step #1: On Page Load
populate drop down 1 with items / values
ex>
Text: ".NET 101"
Value: "1"
Step #2: On Drop 1 Selected Index Changed
store the selected items value
****the index corresponds only to the drop 1 list - don't store this*****
pass the selected value to the stored procedure
EXEC spGetData 1
Step#3: On Page Load --
if(Session["_sectionid"]!=null)
get session value
pass to stored procedure
bind data
clear session for next round
|
|
|
|
|
thanks for the reply @Member9245431 but my objective is to get the seletedvalue of my second dropdwonlist(ddlSection) which i can't get the selected item. every time i put a breakpoint on my Loading event of my page the selectedindex in my ddlSection always reset that's why im still getting the first index which i selected is the second or third item. im sure that there's no one in my function that populates my ddlSection trigger at any event only in my first dropdwonlist(ddlLevel)which fires only on selectedindexchanged event. I burned a lot of time on this issue of mine.
|
|
|
|
|
Hi,
Is it possible if windows tag the clipboard to check if it's related my application or to other application?
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
|
There is two tables.
1)Employee table(slno,empid,empname,projid)
2)Project table(slno,projid,projname)
In combobox projname should be shown, and when we select projname, according to that emp table should be shown.
Using stored procedure.
For me connection string also not working.
|
|
|
|
|
What exactly is your question? What code have you written? What isn't working?
|
|
|
|
|
Mate, I assume that you need show the related employees in the gridview as per the combobox selection.
It is just the matter of reading the selected value from the combobox,
selectedItem = comboBox1.SelectedItem;
Pass this selected value to filter the Employee table and read the results.
Finally, Rebind(); the gridview.
This is the basic logic. Try the above(There are plenty of resources online). If you get any real problem after your own attempt, post them in Questions area. Good luck.
|
|
|
|
|
I started to learn how to write mvc tests from the following site http://www.asp.net/mvc/tutorials/older-versions/contact-manager/iteration-5-create-unit-tests-cs"
However when running the test I keep getting a object not set to instance exception
[TestMethod]
public void CreateRace()
{
RACE race = new RACE();
race.RACE_CODE = 1;
race.Logourl = "dasdad";
race.RegattaCity = "Durban";
race.RegattaProvince = "Kzn";
race.RegattaStreetAddress = "232Chats";
race.MAXPARTICA = 12;
race.SECRETARY_EMAIL = "ssasda";
race.SECRETARY_MOBILE = 1422434;
race.SECRETARY_NAME = "jsjsjs";
race.ENTRYAMOUNT = Convert.ToDecimal(23.58);
race.EVENT_NAME = "sadada";
race.status = "Active";
race.UserId = 1;
race.LATEENTRYAMOUNT = Convert.ToDecimal(23.58);
string eventstart = "2014/05/12 12:02", eventend = "2014/05/17 12:02", entrydeadline = "2014/05/11 12:02", withdrawdate = "2014/05/11 12:02", YachtClubname = "durban";
var result = _service.CreateRace(race, eventstart, eventend, entrydeadline, withdrawdate, YachtClubname, "Kzn");
Assert.IsTrue(result);
}
//Create Service Method
public bool CreateRace(RACE race, string eventstart, string eventend, string entrydeadline, string withdrawaldate,string YachtClubname,string Province )
{
if (!ValidateRace( race,eventstart, eventend, entrydeadline, withdrawaldate,YachtClubname,Province))
return false;
try
{
_repository.CreateRace(race, eventstart, eventend, entrydeadline, withdrawaldate,YachtClubname,Province);
}
catch
{
return false;
}
return true;
}
|
|
|
|
|
I see two possible locations in there. One is that you haven't initialized _service, the other being _repository.
|
|
|
|
|
Thank you for your reply;Is this what you meant by Initialization:
private Mock<IRaceRepository> _mockRepository;
private ModelStateDictionary _modelState;
private IRaceService _service;
[TestInitialize]
public void Initialize()
{
_mockRepository = new Mock<IRaceRepository>();
_modelState = new ModelStateDictionary();
_service = new RaceServiceRepository(new ModelStateWrapper(_modelState), _mockRepository.Object);
}
Unfortunately it still gives me Object not set to an instance on an object error
|
|
|
|
|
Then throw us a bone and do some debugging. Find out which line is throwing this exception. Until you do this, we can't help.
|
|
|
|
|
That's one of the easiest errors to track down. One of the objects you're using is null. It's that simple.
Use the debugger to find out which one. You're getting this error because you're code is assuming that every property and method you're calling is returning an object. One or more of them returned null.
Step through the code line by line in the debugger and hover the mouse over each and every variable to see what it's value is.
|
|
|
|
|
You can set the development environment (Visual Studio) to break where the exception was originally throw (if it's re-thrown) by changing the following setting: "Debug->Exceptions..." and check the Thrown column for "Common Language Runtime Exceptions".
modified 12-Feb-22 21:01pm.
|
|
|
|
|
Goodmorning,
I would like to start my form having the mouse set in the form area (in any position is ok, but in the form) at the start.
Is it possible?
Thanks
|
|
|
|
|
Windows Forms? If so, just set MouseLocation to your desired location.
|
|
|
|
|
MouseLocation is it a proprties? of which object?
|
|
|
|
|
Yes - you have to work relative to the Form Location property, but it's pretty simple:
private void frmMain_Load(object sender, EventArgs e)
{
Cursor.Position = new Point(Location.X + 10, Location.Y + 10);
}
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
{
Point mid = new Point(Width / 2, Height / 2);
Cursor.Position = new Point(this.Left + mid.X, this.Top + mid.Y);
}
Happy Coding...
modified 3-Sep-19 21:02pm.
|
|
|
|
|
I’m developing a Window’s forms application for collecting and graphing historical data and utilizing a monthcalendar control that allows the user to select a day or range of days for graphing (MaxSelectionCount = 7). Additionally, since the user should never be selecting future dates, I have set the maxdate property to today (DateTime.Now).
Utilizing this configuration the user is allowed select any individual valid date (including today) without a problem, AND the user is allowed select any group of “previous” dates without a problem. However, the control will NOT allow the user to select a range of dates that includes today. Any ideas on why this doesn’t work???
I can even set the MaxDate to tomorrow (DateTime.Now.AddDays(1)) with similar results; However, setting MaxDate to the day after tomorrow (DateTime.Now.AddDays(2)) DOES allow the user to select a range including today… But it also lets them select a range of dates that includes tomorrow, and the day after tomorrow can be selected as an individual date…
Kip
|
|
|
|
|
The MaxDate property works up to the exact DateTime that you set: but DateTime.Now includes the hours, minutes and seconds - so setting MaxDate to it pretty much excludes the final date from a range as it has already passed (I think - I haven;t looked at the .NET code). What you need to do is set it to the end of day that you want to include:
myMonthCalendar.MaxDate = DateTime.Now.AddDays(1).Date.AddSeconds(-1); Should do it.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|