|
There's no difference in terms of the response. GET and POST only alter the request.
HTTP Messages - HTTP | MDN[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm implementing asp.net core project. In my Controller class, in its Edit method, I wrote some code like below:
public async Task<IActionResult> Edit(int id, ApplicantViewModel applicant)
{
var formerApplicantType = await _context.Applicant
.Include(a => a.ApplicantTypeNavigation)
.FirstOrDefaultAsync(m => m.ApplicantId == id);
if (id != applicant.applicantvm.ApplicantId)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
if (applicant.applicantvm.ApplicantType == 1)
{
var UpdQuery = from a in _context.Applicant
join p in _context.PersonApplicant on a.ApplicantId
equals p.ApplicantId
where applicant.applicantvm.ApplicantId == a.ApplicantId && applicant.applicantvm.ApplicantType == a.ApplicantType
select new { a, p };
if (formerApplicantType.ApplicantType == 2)
{
Debug.WriteLine("opposite applicantType");
var legalApplicantForDelete = await _context.LegalApplicant.FindAsync(id);
_context.LegalApplicant.Remove(legalApplicantForDelete);
var pa = new PersonApplicant()
{
BirthCertificateNo = applicant.personapplicantvm.BirthCertificateNo,
IssuePlace = applicant.personapplicantvm.IssuePlace,
NationalCode = applicant.personapplicantvm.NationalCode,
Username = applicant.personapplicantvm.Username,
Applicant = applicant.applicantvm
};
using (var context = new CSSDDashboardContext())
{
context.PersonApplicant.Add(pa);
context.SaveChanges();
}
}
else
{
foreach (var x in UpdQuery.ToList())
{
x.a.ApplicantType = applicant.applicantvm.ApplicantType;
x.a.Address = applicant.applicantvm.Address;
x.a.Description = applicant.applicantvm.Description;
x.a.Name = applicant.applicantvm.Name;
x.p.BirthCertificateNo = applicant.personapplicantvm.BirthCertificateNo;
x.p.NationalCode = applicant.personapplicantvm.NationalCode;
x.p.IssuePlace = applicant.personapplicantvm.IssuePlace;
x.p.Username = applicant.personapplicantvm.Username;
}
}
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ApplicantExists(applicant.applicantvm.ApplicantId))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
ViewData["ApplicantType"] = new SelectList(_context.EntityType, "Id", "Id", applicant.applicantvm.ApplicantType);
return View(applicant);
}
In my code I have 3 tables Applicant and PersonApplicant and LegalApplicant. Applicant has one to one relationship with LegalApplicant and PersonApplicant. Eachtime Applicant refers to one of them. They are connected with each other as the primary key {ApplicantID,ApplicantType} and if ApplicantType is 1, Applicant refers to PersonApplicant and if it is 2, Applicant refers to LegalApplicant. In the view, the user should choose from a selectlist about the type of applicant he wants to update. Now my problem is in updating those tables when user wants to change the ApplicantType. For instance, if the user change ApplicantType from LegalApplicant to PersonApplicant then the former record in Legal applicant should be deleted according what I did in the code and a new record should be inserted into PersonApplicant. For doing that I wrote like the above code, But after running the project, it shows me an error which is about not to accept the former applicant record exist and just refers to another table. In my methodology I can not delet the related record in Applicant and again insert a new one ther cause I need the former info about that record. I appreciate if anyone guide me how can I fix this.
|
|
|
|
|
Hi all, I hope I got the right forum...
I can do what the subject states when the comboBox or DropDown is NOT in a gridview, as in the code below which populates the room DDL with the value that was selected in the building DDL
Protected Sub DDLbuilding_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDLbuilding.SelectedIndexChanged
'Create DataTable
Dim dtRooms As New DataTable() ' - Room Numbers
dtRooms.Columns.Add("Room", Type.GetType("System.String"))
'Get Buildings for this campus
RoomTable = RoomAdapter.GetRooms(DDLbuilding.SelectedValue)
'Fill DataTable
For Each RoomRow In RoomTable
dtRooms.Rows.Add()
dtRooms.Rows(dtRooms.Rows.Count - 1)("Room") = RoomRow.Room
Next
'bind DDLroom to datatable
DDLroom.DataSource = dtRooms
DDLroom.DataBind()
End Sub
but when the comboBox or DDL is in a gridview it throws the error "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control".
Here's what I have so far for the gridview comboBox
Protected Sub cbEQName_SelectedIndexChanged(sender As Object, e As EventArgs)
'Get row index of selected comboBox
Dim gvRow As GridViewRow = CType(CType(sender, Control).Parent.Parent, GridViewRow)
Dim index As Integer = gvRow.RowIndex
'Get selected value of selected comboBox
EQname = TryCast(GVnewEquipment.Rows(index).FindControl("cbEQname"), AjaxControlToolkit.ComboBox).Text
'Get new values of next comboBox from selected value of selected comboBox
EquipmentTable = EquipmentAdapter.GetMfg(EQname)
'Create DataTable
Dim dtMfgs As New DataTable() ' - mfgs that are used by Equiptment name
dtMfgs.Columns.Add("mfg", Type.GetType("System.String"))
'Fill DataTable
For Each EquipmentRow In EquipmentTable
dtMfgs.Rows.Add()
dtMfgs.Rows(dtMfgs.Rows.Count - 1)("mfg") = EquipmentRow.mfg
Next
'create ComboBox which will represent GVnewQuipment cbMfg comboBox
Dim CB = DirectCast(GVnewEquipment.Rows(index).FindControl("cbMfg"), AjaxControlToolkit.ComboBox)
'bind cbMfg to datatable
CB.DataSource = dtMfgs
CB.DataBind()
End Sub
Any and help is greatly appreciated!!
Lee
|
|
|
|
|
Hi. I'm implementing asp.net core project. In my controller class I have a query like below that joins two tables.
var UpdQuery = from a in _context.Applicant
join p in _context.PersonApplicant on a.ApplicantId
equals p.ApplicantId
where applicant.applicantvm.ApplicantId == a.ApplicantId // && applicant.applicantvm.ApplicantType == a.ApplicantType
select new { a, p };
I want to get the value of one of Updquery's fields which is called ApplicantType and it is of type int. For doing this, I wrote a query like below to get that value. However it doesn't give me a correct value.
var formerApplicantType = UpdQuery.Select(u => u.a.ApplicantType).SingleOrDefault();
Debug.WriteLine("formerApplicantType:" + int.Parse(formerApplicantType.ToString()));
I appreciate if any one tells me where do I make a mistake?
|
|
|
|
|
There's nothing obviously wrong with the query, other than the fact that you're converting an int to a string just to parse it back to an int :
int formerApplicantType = UpdQuery.Select(u => u.a.ApplicantType).SingleOrDefault();
Debug.WriteLine("formerApplicantType:" + int.Parse(formerApplicantType.ToString()));
int formerApplicantType = UpdQuery.Select(u => u.a.ApplicantType).SingleOrDefault();
Debug.WriteLine("formerApplicantType:" + formerApplicantType);
This is going to be down to the data you're querying, the input you've provided, and what your definition of the "correct" value is.
Since we can't see any of those things, we can't help.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Greetings again,
This is part of the solution that the great Richard provided last week.
The app takes empID and determines if the employee has ever completed the form before.
If this is the first time the employee is compleing the form, then the form is completely blank so employee can complete entire form.
This works great.
It also checks to see if the employee had completed the form before, if yes but not the previous year, then employee name, title, email and employee ID are loaded but the rest of the form is blank so the user can complete the rest of the form.
This also works great.
Here is the part that we are still having problem with.
An employee can complete one gridview control, say GridView1, add an additional row and complete that row.
In this situation, if the employee completed form the previous year, then when the data that the employee had completed the previous year is loaded, it displays the two rows that employee completed for GridView1.
The problem is that all other gridview controls like grvspouse, grvspouse, etc for instance, are are also loaded with two rows even though those rows are blank.
Is there somethin I can change in the attached code that will ensure that those gridview controls like the two examples I showed above, show just one row since they have not been completed before?
Protected Sub txtEmpID_TextChanged(sender As Object, e As EventArgs) Handles txtEmpID.TextChanged
If String.IsNullOrEmpty(txtEmpID.Text) Then
checkusername.Visible = False
Return
End If
' Clear the controls:
'txtEmpID.Text = String.Empty
txteName.Text = String.Empty
txttitle.Text = String.Empty
txtemail.Text = String.Empty
lblStatus.Text = String.Empty
Gridview1.DataSource = Nothing
Gridview1.DataBind()
grvspouse.DataSource = Nothing
grvspouse.DataBind()
grvDiv.DataSource = Nothing
grvDiv.DataBind()
grvReim.DataSource = Nothing
grvReim.DataBind()
grvHon.DataSource = Nothing
grvHon.DataBind()
grvGift.DataSource = Nothing
grvGift.DataBind()
grvOrg.DataSource = Nothing
grvOrg.DataBind()
grvCred.DataSource = Nothing
grvCred.DataBind()
checkusername.Visible = True
dprocessed.Visible = True
lblStatus.ForeColor = System.Drawing.Color.Red
Using Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Using cmd As New SqlCommand("ValidateEmpID", Conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@empID", txtEmpID.Text)
Conn.Open()
Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If Not dr.Read() Then
imgstatus.ImageUrl = "images/Icon_Available.gif"
lblStatus.Text = "This must be the first time you are completing this form. Proceed to complete entire form. If you feel there is a mistake, please contact the office"
txteName.Enabled = True
txttitle.Enabled = True
txtemail.Enabled = True
txtEmpID.Enabled = True
GridPanels.Enabled = True
btnNext.Enabled = True
Return
End If
imgstatus.ImageUrl = "images/NotAvailable.jpg"
txteName.Text = dr("employeeName").ToString()
txttitle.Text = dr("empTitle").ToString()
txtemail.Text = dr("email").ToString()
txtEmpID.Text = dr("empID").ToString()
If dr("previousYear").ToString() = "1" Then
lblStatus.Text = "Please verify your information for accuracy. Then complete rest of the form."
txteName.Enabled = True
txttitle.Enabled = True
txtemail.Enabled = True
txtEmpID.Enabled = True
GridPanels.Enabled = True
btnNext.Enabled = True
fillSourceRecords()
ElseIf dr("thisYear").ToString() = "1" Then
lblStatus.Text = "You have already completed this form. Please close the form. If you feel there is a mistake, please contact the office"
txteName.Enabled = False
txttitle.Enabled = False
txtemail.Enabled = False
txtEmpID.Enabled = False
GridPanels.Enabled = False
btnNext.Enabled = False
Else
lblStatus.Text = "No entries this year, nor the previous year. Please complete the form. If you feel this is a mistake, please contact Clerk to the CEO and BOC at 404-371-3224"
txteName.Enabled = False
txttitle.Enabled = False
txtemail.Enabled = False
txtEmpID.Enabled = False
GridPanels.Enabled = False
btnNext.Enabled = False
End If
End Using
End Using
End Using
End Sub
Private Sub fillSourceRecords()
Dim conn_str As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
conn.Open()
Using sourcecmd As SqlCommand = New SqlCommand()
sourcecmd.CommandText = "uspGetAllRecs"
sourcecmd.CommandType = CommandType.StoredProcedure
sourcecmd.Parameters.AddWithValue("@empID", txtEmpID.Text.Trim())
sourcecmd.Connection = conn
Using ad As SqlDataAdapter = New SqlDataAdapter(sourcecmd)
Dim ds As DataSet = New DataSet()
ad.Fill(ds)
Gridview1.DataSource = ds
Gridview1.DataBind()
grvspouse.DataSource = ds
grvspouse.DataBind()
grvDiv.DataSource = ds
grvDiv.DataBind()
grvReim.DataSource = ds
grvReim.DataBind()
grvHon.DataSource = ds
grvHon.DataBind()
grvGift.DataSource = ds
grvGift.DataBind()
grvOrg.DataSource = ds
grvOrg.DataBind()
grvCred.DataSource = ds
grvCred.DataBind()
End Using
End Using
End Using
End Sub
|
|
|
|
|
Hi -
I know its dumbest question but I want to understand.
I have completed a React Application, which calls a Web Api, the application runs fine with npm start, its all working fine, but when I am deploying the application, how should I set up the start page of the application, I am new to React and I have never been part of the deploying any SPA application? How can I set the start of my react application when I am going to deploy on the Server in my Website folder? Can I change it? How can I change it?
When Web API is deployed separately from the React app, where would the new request first goes, whether it would go to the React SPA or it goes to the Web APIs controller method.
Same questions I have for Vue.js, Angular and Ember, what are the starting pages, how to set them and if we have separate web applications running for the js and Web Api server side logic - where do the request first go when we just type for example: xxxx.com, what's the first page.
I got this question since when I build my Ember project using npm build - its not creating the default.htm or index.html files - so how is it going to the first page? Any help to understand the flow here. I know its dumbest question but want to understand - thank you.
|
|
|
|
|
In Angular, the home page is set in App.Routes.ts.
{ path: "", redirectTo: "home", pathMatch: "full" },
So any wild card path that doesn't match another route gets sent to website.com/home, and the home.routes.ts takes it from there. Or if you type https://website.com/legal, the legal.routes.ts calculates the route.
{ path: "", component: HomeComponent },
{ path: "legal", loadChildren: "./legal/legal.module#LegalModule" },
{ path: "", redirectTo: "", pathMatch: "full" }
This allows typing https://website.com to load the home page https://website.com/home
Or allows sending a link to a page to share such as https://website.com/software/Angular
I suspect your thinking old school, like setting up IIS and setting the programs root folder to start from.
SPA in Setup.cs just tells SPA where the ng build root is, and calls the npmScript "start" in package.json. What SPA services really does is compiles or builds angular when you start the project.
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build:ssr": "ng run jkirkerx:server:dev",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postInstall": "npm rebuild node-sass"
},
The controller say .Net Core V2.2+ if that is what your using for back end logic has it's own routes that you assign to a controller. So this is the Store Controller, and is called by an Angular service as
https://website.com/api/Store/GetBrands/1/8
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]
public class StoreController : ControllerBase {
[HttpGet("GetBrands/{page}/{show}")]
public async Task<GetBrands> GetBrands(int page, int show)
{
return await _brandsRepository.GetBrands(page, show);<br />
}
}
With CORS setup correctly, only the client can call this Url, and if typed in the browser, Angular will reject the request and your Startup.cs will direct the request to the https://website.com/Error
if (env.EnvironmentName.Equals("Development"))
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseWhen(context => !context.Request.Path.Value.StartsWith("/api"), builder =>
{
builder.UseStatusCodePagesWithReExecute("/Error/{0}");
});
app.UseHsts();
app.UseHttpsRedirection();
}
I've only done a Angular app wrapped in .Net Core V2.2+, and the two seem to bounce off each other in terms of Web hosting and protection if you program the Kestrel Web Server in Program.cs and Startup.cs. I could separate the 2 projects from each other and still formulate a solution that works in a Docker Container.
But like I said in the past, designing and building the hosting environment, testing it and fully understanding it is a huge project in itself with very little documentation on how to do it. I learned the hard way on how to program Kestrel, and then do it in a Docker Container. Something I will write a paper on here soon if anyone is interested in it.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
|
I am creating a usercontrol named InvalidCaseUserControl in web forms for a web app. When I run the code in debug mode I am getting the following errors CS0079 The event 'Control.Disposed' can only appear on the left hand side of += or -=
Error CS7036 There is no argument given that corresponds to the required formal parameter 'e' of 'EventHandler'
Error CS0115 'InvalidCaseUserControl.Dispose(bool)': no suitable method found to override
How do I solve this?
public partial class InvalidCaseUserControl : System.Web.UI.UserControl
{
private int _batchNumber;
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Disposed(disposing);
}
}
modified 3-Feb-20 13:46pm.
|
|
|
|
|
The base class doesn't have a method called Dispose which takes any parameters. Perhaps you meant to override the Control.Dispose method[^] instead?
public override void Dispose()
{
try
{
if (components != null)
{
components.Dispose();
}
}
finally
{
base.Dispose();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you for your help. For now this seems to work. I will do more testing as I continue to add to the code.
|
|
|
|
|
Hello: We're hoping somebody here can help point us in the right direction for a web based project we're working on.
Based on user-input, we need to generate a diagram using real world units and render the output to the browser. e.g. the user enters width and height in inches, and we create a rectangle with these units. We've been trying to use SVG, but we're having trouble getting it to scale appropriately.
Appreciate any input you have to offer.
Thanks.
|
|
|
|
|
SVG seems perfect for that. The scale which is displayed on a monitor or which would be printed on a paper depends on the resolution (dpi) of the medium. Usually, for a monitor, it is 96 dpi; for printed documents it could be 300 or 600 dpi, or even more.
I would try to persevere with SVG and try to understand the mechanism which would bring rendered drawing to the appropriate scale.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
Thank you for your reply. It helps to know I'm off in the right direction.
Would it be possible to look at my code to see if you can detect any reason why the SVG isn't scaling to fit inside a div. See the rectangle below:
<div style="width: 600px; height: 500px;">
<svg width="60in" height="15in" viewBox="0 0 60 15" style="border: 1px solid black;">
<line x1="30" y1="0" x2="30" y2="15" style="stroke:rgb(0,0,0);stroke-width:2px" vector-effect="non-scaling-stroke" />
</svg>
</div>
I appreciate your help
|
|
|
|
|
Maybe this will enlighten you:
How to Scale SVG | CSS-Tricks[^]
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
Has anyone used Swagger codegen and done customisation on auto generated .net project files
Manoj
|
|
|
|
|
I have an ASP .NET application that requires Document Mode to default to IE11. I have set the computer local IE11 browser to default to document mode IE11. The problem I have is when I deploy my ASP .NET site to IIS and browse to the site the Document Mode gets changes back to IE7 Default. Because of this my JavaScript does not work. How do I set the IE11 Document mode to IE11 default when I browse to the site and not change it back to IE7 default?
|
|
|
|
|
|
I have turned off the "Display intranet sites compatibility view" so when I open the browser without browsing it remains on IE11 as default. It's only when I browse my website does it change.
|
|
|
|
|
|
I don't see a 'compatibility view' button across the address bar.
|
|
|
|
|
I have added a database to my application and then published it in IIS. I am getting an SQL error and IIS error when trying to browse to the site and have been trying to figure it out all day. I hope you can look and see if you can come up with something. The IIS error is: "Cannot open database "KML" requested by the login. The login failed. Login failed for user 'NT AUTHORITY\SYSTEM'". The SQL error is: "[SqlException (0x80131904): Cannot open database 'KML' requested by the login. The login failed. Login failed for user 'NT_AUTHORITY\SYSTEM'. ] . I hope someone can figure out what the problem is. Thanks.
|
|
|
|
|
|
I am getting an error when I try to get case information from a database (Justice)
Here is the error:
{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{Pragma: no-cache Cache-Control: no-cache Date: Wed, 29 Jan 2020 22:07:12 GMT Server: Microsoft-IIS/8.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Content-Length: 6066 Content-Type: application/json; charset=utf-8 Expires: -1 }}
I need help to solve the error StatusCode: 500 When button is clicked JusticeContoller class is called. This is where I am getting an error on line response=await client.GetAsync("api/GetAllAcceptCAseNumbers/" + candidateCases);
protected async void GetCasesButton_Click(object sender, EventArgs e)
{
if (CaseNumbersTextBox.Text.Length < 1)
{
string myStringVariable = "Case number textbox cannot be empty.";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
return;
}
try
{
#region Get Batch Number
int newBatchNumber = await CandidateCaseController.GetNextBatchNumber();
#endregion
#region Insert entered case numbers in database
foreach (string caseNumber in userEnteredCaseNumberList)
{
EditCandidateCaseModel newCandidate = new EditCandidateCaseModel();
newCandidate.CaseNbr = caseNumber;
newCandidate.EntryStaffUserName = Helpers.Authentication.GetADEmail();
await CandidateCaseController.PostCandidate(newCandidate);
}
#region Get MNCIS info on cases
List<string> smallEnoughStrings = new List<string>();
List<AcceptCaseNumbersModel> mncisDetailList = new List<AcceptCaseNumbersModel>();
List<AcceptCaseNumbersModel> smallEnoughMncisDetailList = new List<AcceptCaseNumbersModel>();
foreach (string smallEnoughString in smallEnoughStrings)
{
smallEnoughMncisDetailList = await FTACaseReseting.Controllers.JusticeController.GetAllAcceptCaseNumbers(smallEnoughString);
mncisDetailList.AddRange(smallEnoughMncisDetailList);
}
#endregion
}
catch (Exception ex)
{
string errorMsg = string.Format("An error has occured in {0}. \nException:\n{1}", "GetCasesButton_Click()", ex.Message);
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + errorMsg + "');", true);
}
}
Here is the class called when button click even happens
public class JusticeController
{
#region Get
public static async Task<List<AcceptCaseNumbersModel>> GetAllAcceptCaseNumbers(string candidateCases)
{
List<AcceptCaseNumbersModel> retVal = new List<AcceptCaseNumbersModel>();
TokenModel tm = new TokenModel();
tm = await TokenController.GetAccessToken();
if (tm.access_token.Length > 0)
{
using (HttpClient client = DataAccess.EstablishConnection(ConfigurationManager.AppSettings.Get("ServiceUri"), ConfigurationManager.AppSettings.Get("ServiceReturnType")))
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tm.access_token);
HttpResponseMessage response = new HttpResponseMessage();
response = await client.GetAsync("api/GetAllAcceptCaseNumbers/" + candidateCases);
if (response.IsSuccessStatusCode)
retVal = await response.Content.ReadAsAsync<List<AcceptCaseNumbersModel>>();
}
}
return retVal;
}
#endregion
}
|
|
|
|
|