|
Please do not post duplicate contents.
Also, do you need to save save html markup here to database? or contents you generated inside html table.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
You are not clearly explaining yourself. What is your issue?
|
|
|
|
|
I don't know if I am in the right place to ask a question in reference to using a variable inside a view. I want the variable to go inside the @Html.EditorFor(model => variable). Any help appreciated. Thanks.
UPDATE:
I think I have solved my problem. My application is used to store internet sites user/password information. The data is stored in data/value pairs. The value is encrypted with my own code. I needed to run the value item through the encryption code so it could be stored in the database. I created another object with data from the database, and compared the two value objects to see if it should be saved. If so the value item was run through the encrypt code. Then the second object was unattached and the edited object saved. Thanks for the help.
modified 19-Jun-17 14:48pm.
|
|
|
|
|
You can have that variable as part of your your view model so you can use it on view. Assuming you have requirement to use it as html helper only per your code you showing in description.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
Vinod,
UPDATE:
I think I have solved my problem. My application is used to store internet sites user/password information. The data is stored in data/value pairs. The value is encrypted with my own code. I needed to run the value item through the encryption code so it could be stored in the database. I created another object with data from the database, and compared the two value objects to see if it should be saved. If so the value item was run through the encrypt code. Then the second object was unattached and the edited object saved. Thanks for the help.
|
|
|
|
|
What do you want to do with the variable ? It can be part of the model. Post a sample code for what you are trying to do.
|
|
|
|
|
John,
UPDATE:
I think I have solved my problem. My application is used to store internet sites user/password information. The data is stored in data/value pairs. The value is encrypted with my own code. I needed to run the value item through the encryption code so it could be stored in the database. I created another object with data from the database, and compared the two value objects to see if it should be saved. If so the value item was run through the encrypt code. Then the second object was unattached and the edited object saved. Thanks for the help.
|
|
|
|
|
I am VERY new to Asp.Net, so bear with my ignorance.
I added an Export button to a page:
<input type="button" value="Export" onclick="location.href='@Url.Action("Export", "Home")'" />
In the controller I added
public ActionResult Export()
{
var data = _dal.GetDashboardInfos(new DashboardInfoQueryArgs());
var d = data.ToList().ToCsv();
var path = Path.GetTempPath();
var fileData = string.Format("{0}ardexport.csv", path);
using (StreamWriter sw = new StreamWriter(fileData, false))
{
sw.WriteLine(d);
}
Process.Start(fileData);
return View("Index", "Home");
}
The CSV open fine, then I get a page load error:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
.
.
.
After the export I would really like to NOT reload (no reason to), or, at the very least just reload the default page.
What I doing wrong here?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Kevin Marois wrote: Process.Start(fileData);
That's not doing what you think it's doing.
The code is writing to a file on the server, and then attempting to open the file on the server. It appears to work when you run it from Visual Studio, but that's just because the server and the client happen to be the same computer in that instance.
As soon as you deploy your code to a real server, you'll either get an exception indicating that there's no application associated with the file type; or the file will open on the server, where nobody will ever see it.
If you want to send the data back to the client, you'll need to send it via a FileResult :
public ActionResult Export()
{
var data = _dal.GetDashboardInfos(new DashboardInfoQueryArgs());
string content = data.ToList().ToCsv();
byte[] bytes = Encoding.UTF8.GetBytes(content);
var result = new FileContentResult(bytes, "text/plain");
result.FileDownloadName = "ardexport.csv";
return result;
}
Unfortunately, this means you can't return a file and redirect. This is a limitation of how the web works - a single request can only generate a single response.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you. Good thing I posted.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I don't really want to redirect.. I just didn't want it to try to load a view called 'export'. I wanted it to stay on the page it's on.
The code you posted seems to work just fine.
Thank you!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hi all,
I am little new to MVC and WebApi, I am here trying to post values of html form to a HttpPost method of Web Api, here how I am using it
$("#btnSave").click(function () {
var defaultText = $("#defaultText").val();
var txtLanId = $("#txtLanId").val();
var txtLast = $("#txtLast").val();
var txtFirst = $("#txtFirst").val();
var txtEmployeeId = $("#txtEmployeeId").val();
var txtEmail = $("#txtEmail").val();
var dtFieldHireDate = $("#dtFieldHireDate").val();
var dtFieldRehireDate = $("#dtFieldRehireDate").val();
var lbxApplicationGroup = $("#lbxApplicationGroup").val();
var lbxReportPack = $("#lbxReportPack").val();
alert(dtFieldHireDate);
alert(dtFieldRehireDate);
alert(lbxApplicationGroup);
alert(lbxReportPack);
$.ajax({
url: "/api/EmployeeAPI",
type: "Post",
data: JSON.stringify([defaultText, txtLanId, txtLast, txtFirst, txtEmployeeId, txtEmail, dtFieldHireDate, dtFieldRehireDate, lbxApplicationGroup, lbxReportPack]),
contentType: 'application/json; charset=utf-8',
success: function (data) { },
error: function () { alert('error'); }
});
});
When I am trying to retrieve those values in the Web Api method, I am getting empty strings, I am not sure what's going wrong here, but any help is going to be very helpful, thanks in advance.
[System.Web.Http.HttpPost]
public string PostAction(System.Net.Http.Formatting.FormDataCollection form)
{
string retValues;
retValues = form.Get("txtLast") + form.Get("txtLanId");
return retValues;
}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
The FormDataCollection expects an x-www-form-urlencoded submission. You're submitting a JSON-serialized array of strings.
If you don't want to change the API method, you'll need to change the script that calls it:
$("#btnSave").click(function () {
var postData = {
defaultText = $("#defaultText").val(),
txtLanId = $("#txtLanId").val(),
txtLast = $("#txtLast").val(),
txtFirst = $("#txtFirst").val(),
txtEmployeeId = $("#txtEmployeeId").val(),
txtEmail = $("#txtEmail").val(),
dtFieldHireDate = $("#dtFieldHireDate").val(),
dtFieldRehireDate = $("#dtFieldRehireDate").val(),
lbxApplicationGroup = $("#lbxApplicationGroup").val(),
lbxReportPack = $("#lbxReportPack").val()
};
console.log("POST", postData);
$.ajax({
type: "POST",
url: "/api/EmployeeAPI",
data: postData,
success: function(data) { console.log("Success", data); },
error: function() { alert("Error"); }
});
});
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I did this but still the values are not being posted at the Post Method of Web Api, do I need to make any change in the Web Api method as well? Please let me know please my friend?
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Check the "network" tab in the browser's developer tools to see what's actually being sent to the server.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
how to use querry string with various methods
|
|
|
|
|
Depends on the methods. Perhaps you could edit your question and explain exactly what you are trying to do.
|
|
|
|
|
HttpRequest.QueryString Property (System.Web)[^]
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
If you look at the Request object in your method (Of course it is a web application) , you will be able to see the QueryString property there and you can retrieve the values from it.
|
|
|
|
|
I need to be able to lock down the URL of a small application so that the client cannot use the URL with multiple devices. I need to be able to assign some type of generated key/license so that if the client purchases 1 URL they can only use that URL on 1 device. This has nothing to do with sessions and or restricting an employee by the device.
Can something like this be done? Can a unique key be added at the end of the URL and save into the device cookies or something like that
Any directions?
|
|
|
|
|
Unique keys can be added to URLs, can be sent via headers, can be stored on the server-side so that when a request comes by the URL is served otherwise a redirect is issued.
There are several ways at doing this, how do you want to do that, is a bit confusing. The thing is, your requirement needs a license, or a process that tells the system whether a user can access this information or not.
ASP.NET doesn't care about purchase systems, licensing, access etc. You have to manage that and tell ASP.NET, how to configure itself to allow/disallow access to certain parts of the application. That said, this is entirely possible, please be more specific or show some code so that we may guide you further.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
If you read the comments to that answer, you'll see that it's retrieving the server's MAC address. As are almost all the other answers on that thread.
If the client is not on the same subnet as the server, there is no way to retrieve the MAC address of the client from the server. There have occasionally been hacks which exploited security vulnerabilities on the client to allow you to retrieve it, but those are fixed almost as soon as they're found.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Please help me... I am stuck up with http post using http request.
I have an asp.net applicaton which is hosted locally in IIS(http:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Test Web Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
function showImage() {
alert('hi');
}
</script>
</head>
<body>
<form id="imageForm" name="imageForm" method="post" action="Default.aspx" >
<input type="text" name="showImage" value="false" />
<input type="submit" name="refresh" value="submit" onclick="showImage();" />
</form>
</body>
</html>
My Default.aspx.cs ;
protected void Page_Load(Object Source, EventArgs E)
{
}
I have a separate c# application which tries to simulate the button click of "refresh" via http post to Default.aspx, here is the code;
string url = "http://localhost/TestWebPage/Default.aspx";
string postDataStr = "showImage=true";
postDataStr += "&refresh=submit";
byte[] postData = Encoding.ASCII.GetBytes(postDataStr);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = postData.Length;
req.Proxy = WebRequest.DefaultWebProxy;
using (var reqStream = req.GetRequestStream())
{
reqStream.Write(postData, 0, postData.Length);
}
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, Encoding.Default);
string pageContent = reader.ReadToEnd();
string status = ((HttpWebResponse)response).StatusDescription;
reader.Close();
responseStream.Close();
response.Close();
My aspx page is already opened in a chrome browser. When the above code is executed, I want the javascript alert in the showImage() function to be displayed in the Default.aspx page in the same browser window itself.
Unfortunately its not happening now... am I missing anything? or is there any good approach to simulate the button click using separate c#?
Please guide.
|
|
|
|
|
You already posted this in the C# forum. Please post in one place only.
|
|
|
|