|
You do it in the View using Razor if that's what your using
@Html.Partial("Name of the partial view in the Views root")
You can place your JQuery file in the "Section Scripts" in the partial view if you have one so that it loads or runs.
If it ain't broke don't fix it
|
|
|
|
|
Thank you very much and for bearing me my friend, but there is one problem I am thinking how can I solve in this,
- as I am making a jQuery call to Web api to load the data into Parent View, the same jquery method is also embedding the Datatable which is going to be bound with the fields in the Partial View. So I want to use this same call from the same parent (means Customer.js) file only I want to bind the fields of the Partial View. Means in the jquery function where I am binding the values of parent page I want to bind the fields of the partial view as well.
- the second question I have is like for example if I am using a table in the partial view I want to change its id depending upon the jquery get object name, for example if I am rending the same partial view twice, and the Web Api returns two different Datatable objects, I will have that information at the jquery call that which object I am assigning to, but I want to change the ids of the fields of the partial view depending upon the DataTable I am binding.
Is there any way I can do these two my friend? If my question is not properly put please let me know my friend? Thanks a lot.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
-- modified 24-May-17 19:39pm.
|
|
|
|
|
I understand what you want to do, I have just never done it. I never thought about using a partial view for data presentation or work form.
I think some critical thinking is required here.
Remember that the Controller is called first to populate a model, then add some ViewData if required.
Then the View is rendered, including your partial view.
Now the HTML is downloaded by the browser and begins to render.
Once the DOM is set in the browser, Ready is called and your JQuery then runs.
Technically, as an example in the Microsoft Owin Security package, I think ViewData is passed from the parent View to the Partial View. This means you should be able to pack a model into ViewData that will be passed along to the partial. I've done it with Sessions, in which I loaded a model into a session for checkout, and I've done it with ViewData as well.
so it you have a ViewData, this would pull the model back out of the ViewData in the partial view.
var names = (model_array_names)ViewData["NameArray"];
And to pack the ViewData["NameArray"] in the controller
ViewData["NameArray"] = model_array_names;
I would just design a better model or form layout first. If you have to make a choice on a form before data is loaded, then I would design HTML containers for all the scenarios, and then fill those containers with an AJAX call via JQuery.
If it ain't broke don't fix it
|
|
|
|
|
how can we get cell_double click event to be fired on gridview in asp.net
|
|
|
|
|
|
Hi all,
I am developing an application that allows users to upload/download/delete files. I have it working but I am struggling to add the following function.
Check if the file already exists in the specified folder,
if the file exists already, return a message telling the user to choose another name.
if the file doesn't exist, save the file in the specified folder.
This is my controller code:
public ActionResult UploadFiles(int? id)
{
CI cI = db.Database.Find(id);
foreach (string upload in Request.Files)
{
if (Request.Files[upload].FileName != "")
{
string path = Server.MapPath("~/App_Data/uploads/" + id + "/");
string filename = Path.GetFileName(Request.Files[upload].FileName);
Response.Write(path);
Request.Files[upload].SaveAs(Path.Combine(path, filename));
}
}
return View("Upload");
}
The upload view:
@{
ViewBag.Title = "Upload";
}
<h2>Upload</h2>
<script src="~/Scripts/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function () {
$('#btnUploadFile').on('click', function () {
var data = new FormData();
var files = $("#fileUpload").get(0).files;
if (files.length > 0) {
data.append("UploadedImage", files[0]);
}
var ajaxRequest = $.ajax({
type: "POST",
url: "",
contentType: false,
processData: false,
data: data
});
ajaxRequest.done(function (xhr, textStatus) {
@ViewBag.Message
});
});
});
</script>
<input type="file" name="FileUpload1" id="fileUpload" /><br />
<input id="btnUploadFile" type="button" value="Upload File" />
@Html.ActionLink("Documents", "Downloads")
|
|
|
|
|
When you have the target file name ("Path.Combine(path, filename)") use File.Exists to check if it exists
File.Exists Method (String) (System.IO)[^]
If it does exists you can return Json from your action, something like {success:false}, and in your ajax call you can examine the result of the call and if it is a json object where success==false then you know the upload didn't work so you can show a message, otherwise do what you normally do with the result.
You'll maybe want to run through all the files first to check for existing files and return the failure message if any exist and if not run through them again to save them.
|
|
|
|
|
Thanks a mill!
Got the basic function working using:
System.Diagnostics.Debug.Write(System.IO.File.Exists(Path.Combine(path, filename)) ? "File exists." : "File does not exist.");
You are a star. I know I should be able to find this info by myself but I am very very early in my development so sometimes it is hard to know what to look for.
Thanks!
|
|
|
|
|
Hi there,
I am new to asp.net . I want to use a singleton class in asp.net application. Scenario is as following:
A user from GroupA and some users from GroupB login to application. I want to use a singleton class to keep info of all logged in users in above scenario. So i can exchange information/data among users through that class. Is that possible ? Assuming that most users will be logged in at same time or fixed time interval.
Thanks.
|
|
|
|
|
What is it you're asking exactly? Are you asking how to implement a singleton, or if a monolithic session tracker/message bus is a good idea (it's not)?
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Thanks 4 ur reply.
I know how to implement and use singleton class. I want to know, will it work in my scenario?
|
|
|
|
|
It will work as long as all users are accessing the site in the same app domain, so on a single machine you'll be ok but your solution won't scale. You'll need to consider threading issues too as the same objects will be being read\written at the same time.
|
|
|
|
|
I have dropdown list in a partial class. The drop down in the partial class is generated on angularjs. Problem is now I wanted to populates the dropdown in the partial view based upon the selection of the value of the dropdown list, present in the view.
I write the following code but it is not working.
1) The dropdownlist selectedchange event in cshtml file..
$("#ddOrd").change(function () {
if ($("#ddOrd option:selected").text() == "ASK") {
$.ajax({
type: 'POST',
url: '@Url.Action("GetPayment")',
dataType: 'json',
data: { Ord: $("#ddOrd").val() }
});
}
})
2) in the controller class I made the following changes...
public JsonResult GetPayment(string ord)
{
List<payment> customPaymentlist = db.Payment.Where(obj => obj.Name== "ASK").ToList();
ViewBag.Payment = db.Payment.Where(obj => obj.Name == "ASK").ToList();
ViewBag.Payment = customPaymentlist;
return Json(customPaymentlist);
}
3) The Partial View Contains the following code in which I haven't change any thing.. copying it for just reference...
{{type.payment1}}
I haven't use angularjs before so I am not clear the details of it. Now GetPayment function fetching the required record but the problem is that it is not populating the same record in the dropdownlist in the partial view. Please suggest any solution.
modified 18-May-17 2:23am.
|
|
|
|
|
Hi,
I am getting the following error??? Please help???
ERROR:
Server Error in '/Online_Book_Shopping' Application.
The remote name could not be resolved: 'smtp.gmail.com'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote name could not be resolved: 'smtp.gmail.com'
Source Error:
Line 60: smt.Port = 587;
Line 61: smt.EnableSsl= true;
Line 62: smt.Send(msg);//Error comes in this line of code
Line 63: lblmsg.Text = "Username and Password Sent Successfully";
Line 64: lblmsg.ForeColor = System.Drawing.Color.ForestGreen;
Source File: e:\Vijaya\Online_Book_Shopping\ForgetPassword.aspx.cs Line: 62
Following is the code:-
using System.Net;
using System.Net.Mail;
using System.Drawing;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
public partial class ForgetPassword : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string username = "";
string password = "";
string constr = ConfigurationManager.ConnectionStrings["CS"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
{
SqlCommand cmd = new SqlCommand("select Name, Password from dbo.RegisteredUsers where Email=@email", con);
cmd.Parameters.AddWithValue("Email", txtemail.Text);
con.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
if (dr.Read())
{
username = dr["Name"].ToString();
password = dr["Password"].ToString();
}
}
con.Close();
if (!string.IsNullOrEmpty(username))
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("nilusilu3@gmail.com");
msg.To.Add(txtemail.Text);
msg.Subject = " Recover your Password";
msg.Body = ("Your Username is:" + username + "<br/><br/>" + "Your Password is:" + password);
msg.IsBodyHtml = true;
SmtpClient smt = new SmtpClient();
smt.Host = "smtp.gmail.com";
System.Net.NetworkCredential ntwd = new NetworkCredential();
ntwd.UserName = "nilusilu3@gmail.com";
ntwd.Password = "";
smt.UseDefaultCredentials = true;
smt.Credentials = ntwd;
smt.Port = 587;
smt.EnableSsl= true;
smt.Send(msg);
lblmsg.Text = "Username and Password Sent Successfully";
lblmsg.ForeColor = System.Drawing.Color.ForestGreen;
}
}
}
}
|
|
|
|
|
First check if there is internet connection at all...
Than try some changes in your code:
smt.UseDefaultCredentials = false;
smt.Credentials = new NetworkCredential("username", "password");
smt.DeliveryMethod = SmtpDeliveryMethod.Network;
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
It is no wonder so much hacking continues when people still store passwords in clear text. Please read Secure Password Authentication Explained Simply[^] and use some proper security on your site. You should also not send passwords via email, there are better, more secure methods, of resetting a user password.
|
|
|
|
|
Don't send email via gmail, don't send passwords via email, don't store passwords in clear text. Literally everything you are doing are things you shouldn't do.
As for the error it is a network error, nothing to do with your code and nothing that can be solved with code. Google the error for more info.
|
|
|
|
|
|
Hi Team,
I am using Telerik version 2013.3.1114.45 in my Asp.net application. Now I have upgraded my version into 2017.1.228.45. After upgradations lot of Telerik functionalities are not working.
Some of the examples I have described what I have faced so far as follows.
Scenario 1:
I am having rad numeric textboxes on my page. I entered the numeric values into the text box and press enter button.
Actual result: value cleared in the textbox (This problem occurred after upgradations)
Expected result: value shouldn't be cleared in the textbox.
Scenario 2 :
When I click the button the rad window needs to be displayed but it's not opening after upgradations.
Scenario 3
Rad grid row selections, tab index for rad grid also not working. The design was collapsed in rad controls.
Note:
If I do any postback, the Telerik controls are working good.
Queries
Whether we can upgrade Telerik version directly from 2013.3.1114.45 to 2017.1.228.45?
Please provide your valuable solutions.
Thanks in Advance!!!
Simiyon A
|
|
|
|
|
That's a commercial toolkit, which presumably comes with support.
Telerik support are the only people who can assist you with bugs in their software.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi All,
I am trying to return a DataSet that has 6 table to a cshtml file from Web Api, that DataSet is created by using the Entities from Entity Framework the reason I am returning the DataSet is I am converting the Entity Collections as Tables and wrapping them in a DataSet and returning that.
But I am getting the following Exceptions, anybody can please help me in fixing it? Here is my Get method Code:
public DataSet Get()
{
DataSet dsAllListsOfForm = new DataSet();
dsAllListsOfForm.Tables.Clear();
dynamic objCollection; DataTable table;
using (AppDevSecEntities ctx = new AppDevSecEntities())
{
objCollection = (from c in ctx.Departments orderby c.DepartmentName select c).AsQueryable();
table = Common.ConvertToDataTable<Department>(objCollection);
dsAllListsOfForm.Tables.Add(table);
objCollection = (from c in ctx.FunctionalCatagories orderby c.FunctionalCatagoryName select c).AsQueryable();
table = Common.ConvertToDataTable<FunctionalCatagory>(objCollection);
dsAllListsOfForm.Tables.Add(table);
objCollection = (from c in ctx.BusinessUnits orderby c.BusinessUnitName select c).AsQueryable();
table = Common.ConvertToDataTable<BusinessUnit>(objCollection);
dsAllListsOfForm.Tables.Add(table);
objCollection = (from c in ctx.Locations orderby c.LocationName select c).AsQueryable();
table = Common.ConvertToDataTable<Location>(objCollection);
dsAllListsOfForm.Tables.Add(table);
}
return dsAllListsOfForm;
}
Any help/suggestion is going to be very helpful, I am really new to the MVC and FrontEnd tools because I was working with Integrations for quite a While, thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
The full error would be helpful.
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.
|
|
|
|
|
Here is the full error message:
{"Message":"An error has occurred.","ExceptionMessage":"The 'ObjectContent1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.","ExceptionType":"System.InvalidOperationException","StackTrace":null,"InnerException":{"Message":"An error has occurred.","ExceptionMessage":"Error getting value from 'UserJobRoles' on 'System.Data.Entity.DynamicProxies.UserJob_8B6D07991013E40D2C8A48D1247E9769FA4695229DBE170A0749E3AB1ADC9D3C'.","ExceptionType":"Newtonsoft.Json.JsonSerializationException","StackTrace":" at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.Serialization.JsonSerializerProxy.SerializeInternal(JsonWriter jsonWriter, Object value, Type rootType)\r\n at Newtonsoft.Json.Converters.DataTableConverter.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer)\r\n at Newtonsoft.Json.Converters.DataSetConverter.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.","ExceptionType":"System.ObjectDisposedException","StackTrace":" at System.Data.Entity.Core.Objects.ObjectContext.get_Connection()\r\n at System.Data.Entity.Core.Objects.ObjectQuery 1.GetResults(Nullable1 forMergeOption)\r\n at System.Data.Entity.Core.Objects.ObjectQuery 1.Execute(MergeOption mergeOption)\r\n at System.Data.Entity.Core.Objects.DataClasses.EntityCollection1.Load(List 1 collection, MergeOption mergeOption)\r\n at System.Data.Entity.Core.Objects.DataClasses.EntityCollection1.Load(MergeOption mergeOption)\r\n at System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.DeferredLoad()\r\n at System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem](TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject)\r\n at System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.<>c__DisplayClass7 2.<getinterceptordelegate>b__1(TProxy proxy, TItem item)\r\n at System.Data.Entity.DynamicProxies.UserJob_8B6D07991013E40D2C8A48D1247E9769FA4695229DBE170A0749E3AB1ADC9D3C.get_UserJobRoles()\r\n at GetUserJobRoles(Object )\r\n at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)"}}}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
This appears to be the important part: "The ObjectContext instance has been disposed and can no longer be used for operations that require a connection."
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.
|
|
|
|
|
indian143 wrote: the reason I am returning the DataSet is I am converting the Entity Collections as Tables and wrapping them in a DataSet and returning that.
So the reason you're returning a DataSet is because you're returning a DataSet ?
Is there an actual reason for doing that? I can't remember what a JSON-serialized DataSet looks like, but I can't imagine it's going to be easier to work with than an anonymous object containing the entities.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|